Comments (8)
At the very least, it should warn the user about it being ignored.
In the best case, it should follow the usual UNIX tool: flags can be used in any order.
from cli.
I'm going to go with (A) because with git
this is an error and it makes it cleaner later to implement top-level flags. Doing this now.
from cli.
Im using cli too and the way I use is the b
option. It also feels idiomatic because I can pass global flags. Example:
$ foo --no-color subcommand -bar -quz 0
Here --no-color
is independent of subcommands. But to do this, I'm all my global flags before I pass it to cli
. I even created a package for it, so filtering can be made easily: https://github.com/fatih/flags
Having said that, as seen it complicates things a little bit, so I agree with @mitchellh here, however it's also nice to be able to use global flags, such as --no-color
.
from cli.
@fatih Yeah we have some global args for some of our projects as well. We preprocess the os.Args
and remove the args that we use, and pass the rest into cli
. So this approach will work.
from cli.
Done!
from cli.
@mitchellh It seems git allows flags before subcommand.
usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[-c name=value] [--help]
<command> [<args>]
Any flag before <command>
is valid. So I think we should allow flags before commands, though it needs to be known to the cli. I think we should add a feature to allow an extend the current global flags --version
and --help
. What do you think?
from cli.
@fatih Git allows only global flags. It doesn't allow subcommand flags before it.
I think extending the global flags might be useful, but there are easy workarounds (pre-processing the arg slice for example).
from cli.
@mitchellh yeah, I'm saying that --version
and --help
are both global flags. Just saying we should have a feature so people can add their own global flags. Because it's really tedious to implement it manually by ourselves.
So for example, say for packer
the output would be in the form :
usage: packer [--template-path] [--version] [--help] <command> [<args>]
Available commands are:
build build image(s) from template
fix fixes templates from old versions of packer
inspect see components of a template
push push template files to a Packer build service
validate check that a template is valid
version Prints the Packer version
Note the --template-path
global flag. This is just an example, but it would have the advantages:
- Help would auto generate the global flags
- No manual pre-processing of commands are needed, this would be built in
--version
and--help
wouldn't be the only global flags, people would have the choice to add their own
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 logic stops at first flag HOT 3
- 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.