Cli: Allow global flags after command

Created on 24 May 2016  路  21Comments  路  Source: urfave/cli

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

arev2 help wanted kinfeature pinned statuconfirmed

All 21 comments

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!

Okay, I see.

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?

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

Also interested in this.

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

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

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!

Oh!!! I just noticed there's 22 馃憤s. Re-opening now 馃搱

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

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.

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

I don't think that this was fixed in v2

Then this issue is available for anyone to work on 馃憤

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.

bump

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.

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.

Closing this as it has become stale.

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.

This is a great idea! We should definitely have this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

odiferousmint picture odiferousmint  路  14Comments

marwan-at-work picture marwan-at-work  路  24Comments

purpleidea picture purpleidea  路  18Comments

asahasrabuddhe picture asahasrabuddhe  路  14Comments

Nokel81 picture Nokel81  路  14Comments