Comments (7)
This seems to be the case with all "global" flags, and I suspect this has actually never worked. It doesn't work for 10a8494 which introduced support for flags before commands. Basically, it looks like if there are no commands present, it never gets to the flag parsing phase. I wanted to be able to follow certain conventions wrt --help
and --version
, but it actually seems difficult to do with cobra.
You can workaround this in your code presently:
rootCmd.ParseFlags(os.Args)
rootFlags := rootCmd.Flags()
rootFlags.Visit(func(flag *pflag.Flag) {
if flag.Name == "help" {
fmt.Println(rootCmd.Long)
rootCmd.Usage()
os.Exit(-1)
}
})
rootCmd.Execute()
I thought about trying to do a PR for this but it doesn't look straightforward to fix.
Update: For whatever reason, rootCmd.Usage()
won't show help
in the list of available commands.
from cobra.
@eparis as of the latest commit, -h was removed from the help template output. Was this intentional or related to this?
from cobra.
it certainly possible i screwed it up and --help disappeared from the help output...
from cobra.
I just built a sample cobra for the first time, and ran into the -h doesn't work but also noticed it wasn't there so I was trying to figure out how to add it.
from cobra.
Nvm @eparis pebcak.
from cobra.
I am not seeing this issue as of the latest build.
from cobra.
Confirmed. Fixed in latest build.
Closing.
from cobra.
Related Issues (20)
- Child command context is not updated when global context changed HOT 2
- [Bug] SetArgs doesn't reset flag value HOT 9
- A research for generating PR checklists in Pull Request Template
- shorthand not working and throw panic while use name works HOT 2
- Plugins: add map to store arbitrary data in `Command` HOT 1
- [doc] Add support for taking in `text/template`s for generating docs HOT 1
- docs: Content of user_guide.md not published at cobra.dev
- Add EnableFlagSorting similar to EnableCommandSorting
- non-boolean flags found on sub commands regardless of order HOT 4
- Fish completion fails due to `eval` and subshell execution during completion HOT 1
- Update ArgLenAt Dash to search for first option with single dash instead of only double dash
- PersistantFlags are lost when calling up PersistentPostRun chain HOT 1
- 'MarkFlagsRequiredTogether' does not work as intended. Am I wrong? HOT 1
- os.Args added as flags to command
- Accessing cobra command structure internally (porting applications which use cobra to android)
- Huge bash completions file that's very slow to source HOT 2
- Data race when using multiple unrelated `cobra.Command` instances HOT 1
- How do I use multiple characters in a short parameter? HOT 5
- Flag special "mark" support
- CheckErr with custom status code
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 cobra.