4 ms·
Cobra https://github.com/spf13/cobra https://github.com/spf13/cobra uses https://github.com/spf13/pflag https://github.com/spf13/pflag, which supports GNU style
by latchkey 2y ago
Cobra https://github.com/spf13/cobra https://github.com/spf13/cobra uses https://github.com/spf13/pflag https://github.com/spf13/pflag, which supports GNU style flags. Cobra has been developed for many years now and has a ton of additional features, like automatically generating the autocompletions and has tons of unit tests.
I'd just use cobra.
- imiric 2y agoCobra is certainly popular, but it has many weird edge cases and limitations. It's been a while since I've used it so I can't recall the specifics, but I do remember it being a very poor experience, both as a developer and as a user. I've had a much better experience with https://github.com/alecthomas/kong https://github.com/alecthomas/kong , and I've heard good things about https://github.com/urfave/cli https://github.com/urfave/cli , so I would recommend those over Cobra.
- latchkey 2y agoKong doesn't explicitly say it supports GNU-style, which is why I didn't mention it.
- peterldowns 2y agoThey all have their warts, but "just pick cobra/kong/cli" is what I go with these days. I'm still partial to Cobra because of the nice autocompletion scripts it generates for me so I get tab-completion for free.
- MrDarcy 2y agoThis is the correct answer. Just use Cobra, the automatic autocomplete is the best UX for users. I’ve also tried all of them. cobra is more than good enough and what issues remain in 2025 are easily and reliably worked around to be non issues.
- networked 2y agoI have used both argp and Kong. I consider them two of the best Go CLI libraries for different reasons. Kong has a full set of advanced functionality like flag groups and associating environment variables with options. It is highly useful in a larger project with a complex CLI. For a simple command-line interface, I prefer argp's small API and defaults, like exit with status 2 on bad usage. (Disclosure: I contributed this default to argp.) Kong 1.7 has a disadvantage when it comes to negative numbers. argp parses `foo --bar -1` as `foo --bar=-1` the way you expect when `--bar` takes a value, but Kong treats `-1` as a flag. Edit: Expanded the first paragraph.
- acmj 2y ago> argp parses `foo --bar -1` as `foo --bar=-1` the way you expect when `--bar` takes an value, but Kong treats `-1` as a flag. This seems a bug in Kong. Has someone reported it?
- networked 2y agoYes, see https://github.com/alecthomas/kong/issues/315 https://github.com/alecthomas/kong/issues/315. It may be nontrivial to change.
- donatj 2y agoYes! People love Cobra and yet every time I've used it, it's felt super janky and unreliable at actually doing what you think it should. Not a fan.
- programd 2y agoI’ll second that. Cobra is the industrial strength flag parsing package most of the professional Go ecosystem has settled on. It’s the boring choice in the best sense of the word. Use it and move on with life.
- hujun 2y agoone thing I liked about cobra is the auto complete support, but I don't like the manual process of define command and parameter and not easy to extend, so I wrote https://github.com/hujun-open/myflags https://github.com/hujun-open/myflags, it is built-on top of cobra but allow uses a struct to define all commands/args and also easily to extend support new types (even existing types)