urfave/cli

Compatibility for cli.Context and context.Context

ptth404 opened this issue · 2 comments

While cli.Context embeds context.Context sea time it overrides Context.Value notation so that thee standard Context interface isn't implemented

With that calling

var ctx context.Context = // WithValue WithCancel etc
command.Run(context.WithValue(), os.Args)

how is it supposed to access a standard Context interface in any downstream action calls which are injected with *cli.Context one.
E.g

...
Action(ctx *cli.Context) error {
  var  stdCtx context.Context = ... // resolve from ctx
  net.DialContext(stdCtx, ...)
}

@ptth404 You should be able to do

Action(ctx *cli.Context) error {
  var  stdCtx context.Context = ctx.Context
  net.DialContext(stdCtx, ...)
}

and also

  ctx.Context.Value(..)

will return the value you have set on the context

Ah I see. Thank you @dearchap