Comments (3)
Without having a deeper understanding of the flag package in use (since this library has no opinion on it, it just passes []string
), we can’t tell whether -h
is a single flag or if baz
is an argument to -h
. If you’re using the Go standard flag
package, its allowed for -h baz
to be an argument to -h
.
However, this cli library DOES handle -h
as a special case (for help). In that case, I think its a valid question if whether this should be help for foo bar baz
… and I can see that being totally reasonable.
So, if this issue is talking about flags generally, I don’t think this behavior can be changed. But if we’re talking about the help flag specifically there is something here I think.
Please let me know if I’m misunderstanding.
from cli.
Hey @mitchellh , the issue is focusing on flags generally, not specificallly -h
which was used just as an example taken from the test case. I completely understand your point about the trailing argument possibly being an argument for the flag, however, in this case, it is a registered command.
The behavior I am proposing would be to identify foo bar baz
as the subcommand when a flag comes before baz
, e.g. foo bar --myflag baz
, since foo bar baz
was registered as a command for the CLI. If the arguments that follow the first flag are not part of a registered command, it continues to behave like it does today.
from cli.
FWIW over in Terraform we are intentionally making a distinction between options that appear before the command (global options) and options that appear after the command (command-specific options) and so I think I agree with @mitchellh that making this library itself try to recognize options prior to the command could have adverse affects on existing callers making different assumptions.
In the case of Terraform, we achieve this in a kinda-awkward way of pre-analyzing the original args, noticing the index of the first non-flag argument, and then splitting the args slice into a "global flags" portion and an "everything else" portion. We then pass the global flags portion to the Go flags
package and the "everything else" portion to mitchellh/cli
. The individual subcommands then in turn separately call the Go flags
package again to analyze the command-specific options after mitchellh/cli
already did the command handling. Given that, certain changes implemented inside mitchellh/cli
might not be breaking for Terraform, since Terraform is already effectively "hiding" the global flags portion from mitchellh/cli
.
from cli.
Related Issues (20)
- Root command
- Replace current completion generation package with something else HOT 1
- Sporadic test failures in "TestCLIRun_printCommandHelpSubcommands" HOT 5
- please tag and version this project HOT 9
- Top level help shows all subcommand children HOT 2
- Compatibility with standard library `flag` package HOT 3
- Generate help text from command options HOT 2
- Nested Subcommand Help HOT 3
- Flag named version causes application version to be printed incorrectly HOT 1
- Mark commands (and flags) as hidden HOT 5
- panic if a subcommand is wrapped in double quotes and contains spaces HOT 2
- is there support for interactive mode? HOT 3
- default subcommand throws stack overflow HOT 2
- 1.0.0: FAIL: TestCLIAutocomplete_subcommandArgs/RE HOT 1
- Versus cobra cli HOT 1
- How to write shell completion function in Go
- Subcommand parsing: "fooasdf -o=foo" is incorrectly identified as the subcommand "foo"
- Update github.com/Masterminds/sprig HOT 1
- Add flags dynamically HOT 1
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.