mow.cli icon indicating copy to clipboard operation
mow.cli copied to clipboard

Position-independent options

Open schmich opened this issue 6 years ago • 4 comments

From what I can tell, there is no way to have a single-declaration global option that applies across all subcommands (i.e. its position on the command-line doesn't matter).

For example, let's say I have a command-line program foo which has subcommand bar which has subcommand baz. I can invoke this as foo bar baz.

Now, let's say I wanted to add a verbose logging flag -v which applies regardless of command/subcommand. Ideally, then, the following would be equivalent (I could specify the flag anywhere on the command-line):

  • foo -v bar baz
  • foo bar -v baz
  • foo bar baz -v

I'd like to do this without having to define a BoolOpt on foo, bar, and baz. Is there currently a way to do this by just defining a single global BoolOpt?

In my actual use case, I have four levels of commands (i.e. foo bar baz quux --opt waldo). I would like to be able to specify verbosity (-v, -vv, -vvv) as well as remote connection strings (--connection tcp://192.168.1.100:9000) without needing to worry about their position.

Thanks for your work on this library. It's a boon for the community, and I find myself reaching for it often.

schmich avatar Dec 01 '17 13:12 schmich

@schmich Thank you for your kind words and for raising this issue.

It's been a while now that I have been thinking about this idea, ie. something similar to Cobra's persistent flags.

I'm accepting this feature request as I agree it's a "very nice to have". No promises though on when this would be implemented: I've been very bad a keeping them in the past 😆

jawher avatar Dec 01 '17 13:12 jawher

I appreciate the consideration, and I totally understand the "no promises" aspect.

schmich avatar Dec 02 '17 02:12 schmich

@jawher Is there any news about this feature?

mozillazg avatar Jan 12 '18 15:01 mozillazg

@mozillazg sorry, but I haven't been able to look at this yet.

jawher avatar Jan 18 '18 12:01 jawher