-
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
Allow flags to come after arguments #1950
Comments
Additional context: With multi-command binaries it's pretty common pattern to do the "config the command" first:
and then when using it to just put subcommand after
or outright alias it
"POSIX compatbile" is not good. People are not POSIX compatible. |
It's not. |
@XANi I dont see how your example relates to this issue. |
@fiatjaf Please make sure that there is a field that can be set in Command to enable the behavior. Also make sure you have test cases for
where subcmd1 defines these flags and redorder is configured ONLY on that subcommand. Unless you are strictly expected this usage only for single level subcmd. I anticipate that people will ask why it does not work for 2-3 level sub commands. This has to be thought out more thoroughly. |
This is my feature request, that PR is just one possible but humble attempt at implementing it. I'm sure people with more experience with this code can deal with this better, hence this feature request. |
@fiatjaf you may submit the PR and we can merge it but eventually over time it is upto the maintainers to maintain this code and move it forward. So I want to make sure we have a firm foundation since this is not a simple feature. |
Thanks for weighing in @dearchap 🎉 I'm trying to think through an example which allows a
Then the re-order logic is "just": parse flags and return them to the position where they are "registered", i.e. We just need to figure out a precedence convention for flag names overlapping? Perhaps it is "local wins"? Thoughts? |
@decentral1se Thank you for the example. The example supposes that these are bool flags correct ? If you had this
for example we wouldnt reorder since foo is an int flag ? It starts getting tricky. So say we support only bool flags and we have shortoptionshandling enabled we would need to parse out
I think we need to start working on #1273 which would provide a foundation for this behavior. One of pre-exec functions would allow users to add flags dynamically and another of those pre-exec functions would do reordering. |
I hit the issue urfave/cli#1950 with urfave/cli, which makes it hard to Allow flags to come after arguments. Hence, shifting to make use of Cobra as it allows a little more flexibility. Signed-off-by: Steve ESSO <[email protected]>
I hit the issue urfave/cli#1950 with urfave/cli, which makes it hard to Allow flags to come after arguments. Hence, shifting to make use of Cobra as it allows a little more flexibility. Signed-off-by: Steve ESSO <[email protected]>
Fixed in #1987 |
Whoa! Thank you very much! |
Holy shit, incredible work @dearchap 🎉🎉🎉 |
Checklist
What problem does this solve?
cli -s file.txt
andcli file.txt -s
should work the same way because having to strictly type the flags before the arguments is annoying. Most unix utils allow flags after arguments so people are used to that pattern and a thing that is obviously a flag shouldn't be interpreted as an argument just because it comes after another argument.Solution description
cli -s file.txt
andcli file.txt -s
should work the same way.cli -s file.txt
andcli --foo=bar file.txt -s -v --whatever=something
should work the same way.Describe alternatives you've considered
I've tried switching to other CLI frameworks, but they are all much worse than this except in this aspect.
I've tried frontporting a feature from v1 that reordered arguments manually before parsing them: #1928 (currently using this with a custom fork and
replace
).The text was updated successfully, but these errors were encountered: