cli icon indicating copy to clipboard operation
cli copied to clipboard

Ability to add context values

Open nejtr0n opened this issue 8 months ago • 9 comments

Checklist

  • [x] Are you running the latest v3 release? The list of releases is here.
  • [x] Did you check the manual for your release? The v3 manual is here.
  • [x] Did you perform a search about this feature? Here's the GitHub guide about searching.

What problem does this solve?

In old versions we could add context fields in Before function like this

  Before: func(c *cli.Context) error {
      db := "example"
      c.Context = context.WithValue(c.Context, "db", db)
      return nil
  },

It's useful for example for passing logger through all commands.

Solution description

Add some middleware layer to command with signature

func(ctx context.Context, command *cli.Command) func(ctx context.Context, command *cli.Command)

where we could modify passing ctx

Describe alternatives you've considered

Return back Context field to command

nejtr0n avatar Jun 24 '24 17:06 nejtr0n