Comments (11)
It's not.
from cli.
@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
cmd subcmd1 subcmd2 -f -s -X
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.
from cli.
Additional context:
With multi-command binaries it's pretty common pattern to do the "config the command" first:
cli --server 1.2.3.4 --password-file ~/.cli/production.creds
and then when using it to just put subcommand after
cli --server 1.2.3.4 --password-file ~/.cli/production.creds ls --help
cli --server 1.2.3.4 --password-file ~/.cli/production.creds show
cli --server 1.2.3.4 --password-file ~/.cli/production.creds show --filter asd
or outright alias it
alias cli-prod cli --server 1.2.3.4 --password-file ~/.cli/production.creds
cli-prod ls --help
cli-prod show
cli-prod --filter asd
"POSIX compatbile" is not good. People are not POSIX compatible.
from cli.
In v3(alpha), this is already supported. You can verify it using: go get github.com/urfave/cli/v3
.
from cli.
@BlackHole1 #1717 (comment) #976 (comment)
from cli.
Additional context:
With multi-command binaries it's pretty common pattern to do the "config the command" first:
cli --server 1.2.3.4 --password-file ~/.cli/production.creds
and then when using it to just put subcommand after
cli --server 1.2.3.4 --password-file ~/.cli/production.creds ls --help
cli --server 1.2.3.4 --password-file ~/.cli/production.creds show
cli --server 1.2.3.4 --password-file ~/.cli/production.creds show --filter asd
or outright alias it
alias cli-prod cli --server 1.2.3.4 --password-file ~/.cli/production.creds
cli-prod ls --help
cli-prod show
cli-prod --filter asd
"POSIX compatbile" is not good. People are not POSIX compatible.
@XANi I dont see how your example relates to this issue.
from cli.
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.
from cli.
@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.
from cli.
Thanks for weighing in @dearchap 🎉
I'm trying to think through an example which allows a ReorderFlags: true
to be set on the root command which is then propagated to all sub-commands. If we take the following example:
# rough definition
cli [--global] sub1 [--foo] sub2 [--bar] sub3 [--baz] arg1
# user chaotically types while hacking
cli sub1 sub2 --foo sub3 --bar arg1 --baz --global
# transparently reordered
cli --global sub1 --foo sub2 --bar sub3 --baz arg1
Then the re-order logic is "just": parse flags and return them to the position where they are "registered", i.e. Flags: []cli.Flag{fooFlag}
. There is no guessing what the user wants and we follow the logic of the *cli.Command
.
We just need to figure out a precedence convention for flag names overlapping? Perhaps it is "local wins"?
Thoughts?
from cli.
@decentral1se Thank you for the example. The example supposes that these are bool flags correct ? If you had this
cli sub1 sub2 --foo 10 sub3 --bar arg1 --baz --global
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
cli [--global] sub1 [-f] sub2 [-b] sub3 [-z] arg1
cli sub1 sub2 sub3 arg1 --global -fbz
to
cli --global sub1 -f sub2 -b sub3 -z arg1
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.
from cli.
@dearchap that's a good point about non-bool flags. Yeh, I guess it's just the same rule: follow what is registered on the flag (vs. the command this time) - does it accept an argument? then bring that with the sort? Will try manual test along with #1928 great work @fiatjaf
from cli.
Related Issues (20)
- Ensure `go mod tidy` works as expected HOT 1
- Target `stable` and `oldstable` in main CI
- Flags are alphabetically sorted when using categories HOT 3
- Should I expect completion of nested command's flags to work? HOT 31
- AfterFunc execution details HOT 7
- Remove [command [command options]] from help text if there are no sub commands HOT 3
- Default `cli.App.Usage` behaviour is very hard to override and leads to ugly help HOT 1
- Allow omission of default text in help text HOT 2
- Is the "cant duplicate this flag" error (v3) makes sense? HOT 2
- Ability to add context values HOT 8
- What is the purpose of `normalizeFlags`? HOT 3
- Bug in v3: Count is off by 1 HOT 6
- Shell completion works wrongly even if double dash `--` are included in arguments HOT 1
- automatic version flag collides with verbose flag HOT 11
- The document includes broken links HOT 2
- BoolFlag Count and/or compound not working HOT 3
- Strange behavior of CLI flags HOT 4
- Propagate HideHelpCommand to sub-commands HOT 1
- V3 has no `app.ToMarkdown()` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cli.