-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v2 feature: allow flags after arguments #976
Comments
Habe you tried setting the flags on the root of the app rather than the command itself? |
See #585 |
It appears that urfave/cli.v2 does not allow flexible placement of flags (before or after args): urfave/cli#976
It appears that urfave/cli.v2 does not allow flexible placement of flags (before or after args): urfave/cli#976
A lot of CLI tools supports flags after arguments. Today switch one of my application to this package and fount this feature is not supported. |
@AudriusButkevicius #585 isn't the same as this issue. |
This is still a problem, @AudriusButkevicius is it possible to re-open this issue? |
@AudriusButkevicius ran into this today with v2 and v3 and noted that v1 had the desired behavior. Is there an appetite to re-open this? We're looking to migrate an existing CLI off of cobra and to urfave/cli as this library is simpler, but it would be a breaking change to have to require all of our users to start placing their flags before the args, so we're unable to if this issue is not resolved. It doesn't make sense for us to have command-specific flags placed on the root application and thus available to the entire application to achieve this behavior. |
Any updates on this issue? Will this be fixed in v3? |
We are still waiting on a flag parser replacement for this. |
I hope this is fixed soon |
Highly unlikely . We've decided to keep the current parser as it is . V3 had support for persistent flags which allows flags to be placed anywhere in the command chain (but not after args) |
Well I am using V3, even though it isn't documented, will this ever be added? It's such a basic thing and the user will most likely be confused why the flags aren't doing anything |
ya, please support flags anywhere |
I've opened an official feature request for this for v3, which is the only way maintainers will consider fixing it. Please upvote it if you still want it: #1950 There is also a branch and a PR that kinda works linked there that I'm using myself. |
Checklist
What problem does this solve?
I am writing a program which is invoked by another program (openvpn up-script) and it is invoked in a very specific way. I really like this library, so I'd like to be able to use it as a command line parser. The problem is that it seems that all flags must appear before all options.
In my specific case, openvpn will always call your script with exactly 10 arguments, then you can configure it to pass additional arguments. This would result in an os.Args similar to this:
{"tun0", "1", "2"..."10", "--flush"}
. The--flush
is the flag that I'd like to be able to process with this library.It seems like all flags either take no arguments (
BoolFlag
) or take one arugment (StringFlag
).I've needed this for other projects, but having it for this project would be really great.
Solution description
an
os.Args
value of{"a", "--bool-flag", "--string-flag", "abc", "b"}
should have:ctx.Args() --> {"a", "b"}
ctx.BoolFlag("bool-flag") --> true
ctx.StringFlag("string-flag") --> "abc"
Describe alternatives you've considered
Not using this library for some of my projects
The text was updated successfully, but these errors were encountered: