cli icon indicating copy to clipboard operation
cli copied to clipboard

Allow global flags after command

Open fgblomqvist opened this issue 8 years ago • 21 comments

This is just a suggestion, but to me it seems logical to allow global flags after the command as well, not only before it.

For example, if you have a verbose flag, -v: myapp -v server vs. myapp server -v

To me the second one does visually make more sense. Are there cases when this is a bad idea (and therefore the reason to why this is not how it is currently implemented)?

fgblomqvist avatar May 23 '16 22:05 fgblomqvist

Hi @fgblomqvist, I agree with you completely. Unfortunately this is baggage that we carry from using the Go stdlib flag library (which stops parsing the moment it hits a non-flag) so we cannot support it unless we were to rip that out and do our own flag parsing (which we have discussed a bit, but is a non-trivial effort). You can see some more conversation about this in #355.

I'll leave this open as a future enhancement though!

jszwedko avatar May 24 '16 03:05 jszwedko

Okay, I see.

fgblomqvist avatar May 25 '16 18:05 fgblomqvist

The core flag package is BSD licensed, so perhaps the easiest fix would be to include a fork of said package, modified to support intermixed arguments/flags. This has the benefit of keeping the API identical, making the integration simpler than a rewrite or using a different 3rd-party package. Does this sound reasonable?

hackergrrl avatar Sep 14 '16 20:09 hackergrrl

@noffle mmm, that is not a bad idea given the tradeoffs. I'll try to give that a shot in the near future.

Thank you for the suggestion!

jszwedko avatar Sep 14 '16 21:09 jszwedko

Also interested in this.

0xdeafcafe avatar Feb 13 '17 21:02 0xdeafcafe

Bump up for this one too ! But in the meantime, @jszwedko : Thank you so far for the good job you've done ;)

nikkolasg avatar Sep 30 '17 19:09 nikkolasg

wondering if this issue is still up for a fix :)

marwan-at-work avatar Jun 14 '18 03:06 marwan-at-work

Given that this is from last year, I think I'm comfortable closing it 🙂 feel free to re-open / open a new issue / comment in support if there's still interest here!

coilysiren avatar Aug 17 '19 09:08 coilysiren

Oh!!! I just noticed there's 22 👍s. Re-opening now 📈

coilysiren avatar Aug 17 '19 09:08 coilysiren

This may have been fixed by v2? I'd appreciate if someone could investigate that 🙏

🔗 => https://github.com/urfave/cli/releases/tag/v2.0.0

coilysiren avatar Nov 27 '19 07:11 coilysiren

I loved cli library before but this issue of not able to inter-mix arguments and flags is a bit problematic.

To make things worse, certain earlier version used a reordering hack (see above "hack to sidestep urfave/cli#427" which I kind of liked) but this change was later reverted, causing the behavior to vary greatly between versions. I understand that there are bugs regarding this both ways, but the Unix-y default should always be allowing mixing.

I had to track down bugs where cli are suddenly not able to extract flag values where earlier versions worked. Switching to cobra for now.

tanghaibao avatar Dec 12 '19 07:12 tanghaibao

I don't think that this was fixed in v2, I also don't think that "local" flags are supported after the first non-flag

Nokel81 avatar Mar 05 '20 19:03 Nokel81

I don't think that this was fixed in v2

Then this issue is available for anyone to work on 👍

coilysiren avatar Mar 06 '20 08:03 coilysiren

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

stale[bot] avatar Jun 04 '20 08:06 stale[bot]

bump

Nokel81 avatar Jun 04 '20 12:06 Nokel81

This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant.

stale[bot] avatar Jun 04 '20 12:06 stale[bot]

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

stale[bot] avatar Sep 02 '20 13:09 stale[bot]

Closing this as it has become stale.

stale[bot] avatar Oct 02 '20 22:10 stale[bot]

https://github.com/ipfs/ipget/blob/186b8ebaadd38ac340a7e07d59fa271732a8ec53/main.go#L111

ghost avatar Oct 19 '20 16:10 ghost

This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant.

stale[bot] avatar Oct 22 '20 01:10 stale[bot]

This is a great idea! We should definitely have this

coilysiren avatar Jan 15 '21 20:01 coilysiren

Okay this feature is confirmed for v3. I'd like more feedback on this. Say we define a flag for top level command

./app -v cmd1
./app cmd1 -v

We expect both of these to behave the same. Does this work for subcmd as well i.e if a flag is defined for a cmd it should be available for subcmds as well ?

./app cmd1 --foo subcmd1
./app cmd1 subcmd1 --foo

However

./app --foo cmd1 subcmd1

shouldnt work.

Do we want to specifically list flags as "global" so that only those can be strewn throughout the cmdline. So for example if we define two flags f1 and f2 with f2 marked as "global"

./app cmd1 subcmd1 --f2
./app cmd1 --f2 subcmd1 
./app --f2 cmd1 subcmd1

should all work but not

./app cmd1 subcmd1 --f1
./app cmd1 --f1 subcmd1 

dearchap avatar Oct 31 '22 20:10 dearchap