jawher / mow.cli

A versatile library for building CLI applications in Go
MIT License
872 stars 55 forks source link

Position-independent options #64

Open schmich opened 6 years ago

schmich commented 6 years ago

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):

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.

jawher commented 6 years ago

@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 😆

schmich commented 6 years ago

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

mozillazg commented 6 years ago

@jawher Is there any news about this feature?

jawher commented 6 years ago

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