What does HackerNews think of cobra?

A Commander for modern Go CLI interactions

Language: Go

#3 in Go
#2 in Go
I dug around my refs and I was about to recommend https://clig.dev/, but I see you've already found it. It's a great little reference to have when building a CLI. I typically read the code for other CLIs, particularly those written with the framework I'm using. The last framework I used was Cobra [0], and I studied how others did theirs:

- https://cs.github.com/?scopeName=All+repos&scope=&q=github.c...

[0]: https://github.com/spf13/cobra

OP here. There are a few projects that I wasn't able to work into the story that I think are worth a mention (though some of them are in that Awesome Terminals round-up linked in the article).

The Cobra library is a huge one: https://github.com/spf13/cobra

Other stuff worth a look includes:

Tmux: https://github.com/tmux/tmux Kitty: https://github.com/kovidgoyal/kitty Alacritty: https://github.com/alacritty/alacritty

I'm sure there's lots of other stuff I don't know about as well.

https://github.com/spf13/cobra seems to be the most comprehensive, but honourable mentions go to all of the rest.
Ok, now, what languages beside Python and Go provide Command line argument parsing? And Go doesn't do that in a `professional` way. You either write your own, which can easily turn into a clusterfuck or use a third party library. Even in Go, people use cobra[1]. Also embedding a lot of functionality in a standard library isn't great as well, because if some vulnerability is found, it's really hard to patch it, because you need to push versions and (for example on Linux) some distro maintainers won't push it for `stability` etc. A standard library should provide basic functionality (in most general areas), but not very advanced one.

[1] https://github.com/spf13/cobra

Cobra (https://github.com/spf13/cobra), which is a pretty popular library for Go CLI applications, behaves more like classical GNU tools. It also offers usage/help autogeneration and autocompletion for popular shells.

Not sure about the relevant point on compact short options syntax as in `tar -xvzf archive.tgz` though... (edit) after a quick & sloppy test it seems to work as expected

Most popular Go CLIs use https://github.com/spf13/cobra

i.e. Docker / K8s / OpenFaaS and similar

My impression is that nobody bothers with the Go flags package and most people use the POSIX compatible pflag [1] library for argument parsing, usually via the awsome cobra [2] cli framework.

Or they just use viper [3] for both command line and general configuration handling. No point reinventing the wheel or trying to remember some weird non-standard quirks.

[1] https://github.com/spf13/pflag

[2] https://github.com/spf13/cobra

[3] https://github.com/spf13/viper

Go is a particularly good language for CLI's I have found. At least compared to Java/C#/Python.

It's reasonably fast, compiles down to a simple to distribute binary, and the language is forgiving enough that you can do exploratory programming in it. Go-routines make it especially easy to deal with network calls in it as well. For anything that needs absolute performance though look elsewhere, but even then Go might be a good choice for prototyping.

I actually started learning Go with CLI applications. I have found that https://github.com/spf13/cobra tends to be one of the better CLI helpers you can get into but https://github.com/jpillora/opts is one I have been meaning to try following a presentation I saw on it once.

Since everyone else is throwing out recommendations I personally think https://github.com/spf13/cobra is the best CLI templating system, especially because of how well it pairs with https://github.com/spf13/viper.

Large projects like Hugo and Kubernetes have used Cobra to build their CLI tools, and it's fairly light as well even if you need simpler usage. We use it at my workplace simply for wrapping our microservices and the few commands (serve, migrate, etc)

This is what you're looking for: https://github.com/spf13/cobra They are many libs that do that, you probably didn't search very long ...
I've found that Cobra[0] does pretty much everything I've needed via a reasonable API, but I'll admin I'm not fussy about CLI utility behavior.

[0] https://github.com/spf13/cobra

Always interesting to see what CLI library is used. Looks like another feather in the cap of https://github.com/spf13/cobra. I would love to hear why they chose cobra over something like https://github.com/urfave/cli
Looking through the repo's dependencies (https://github.com/stripe/stripe-cli), it seems they are using the GO CLI framework Cobra (https://github.com/spf13/cobra).
For servers I prefer using: https://github.com/alecthomas/kingpin, allows you to really nicely expand based on main arguments with flags. Also, setting defaults is a joy.

For CLIs - https://github.com/spf13/cobra.

However, will definitely try out Docli whenever I start building something new :)

Seems like Cobra is pretty well established in this space - https://github.com/spf13/cobra

Tho admittedly it works in reverse; it generates the doc/help info rather than parsing it into an AST. It addresses the “boilerplate” issue with code gen as well, but it has a CLI to generate code that’s pretty powerful.

For instance, how does docli handle subcommands? How about global vs command specific flags? For any case beyond the basic single command CLI, it seems like there would need to be all sorts of magic and non-obvious formatting requirements on the doc string.

Are you familiar with https://github.com/spf13/cobra? It's used by a few heavy hitters (kubernetes's kubectl) and it provides you a bit of help with bash completion: https://github.com/spf13/cobra/blob/master/bash_completions....

I just added bash completion to a few internal tools that work with kafka, basically just autocompleting topics. It was a little harder than I would have liked (who wants to write all that bash), and I had to fix a bug in Cobra, but overall it wasn't that bad.

I'm actually at Gophercon right now, if anyone wants to hack on Cobra at the community day on Thursday to make this easier, shoot me an email (@gmail).

You can make modern CLI tools today with great discoverability, there are a couple of great frameworks that makes this possible like Click[1] for Python or cobra[2] for Go.

[1] http://click.pocoo.org/6/

[2] https://github.com/spf13/cobra

This is written in Go. I'm not sure this uses cobra, but you could start easily by writing basic CLI tools using cobra[0]

[0] - https://github.com/spf13/cobra

Go has been a game changer for me also. There is also a very good package https://github.com/spf13/cobra that can make the development of complex CLIs easier.
It's certainly worth looking at the standard flag package (http://golang.org/pkg/flag/) if you just need flag parsing.

I've also heard good things about https://github.com/spf13/cobra and https://github.com/codegangsta/cli.