Hacker News new | past | comments | ask | show | jobs | submit login

Cobra 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 , and I've heard good things about https://github.com/urfave/cli , so I would recommend those over Cobra.




I 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.


> 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?


Yes, see https://github.com/alecthomas/kong/issues/315. It may be nontrivial to change.


They 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.


This 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.


Yes! 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.


Kong doesn't explicitly say it supports GNU-style, which is why I didn't mention it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: