Hacker News new | ask | show | jobs
by dashwav 2211 days ago
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)

3 comments

Cobra is actually probably the worst CLI package to choose, because it encourages/forces you into a globals-based architecture.

https://pkg.go.dev/github.com/peterbourgon/ff/v3/ffcli is one that I've been using recently, which has been a lot nicer.

Don't think cobra and viper should be the default CLI framework. They're useful but overkill for most use case. I personally find that the standard lib has more than enough power to do everything.
Great stuff! Does anything like Cobra exist for Java?
Absolutely! I've used picocli[1] and airline[2]. There is always the Apache Commons CLI if you feel like building it all yourself.

1: https://picocli.info/

2: https://github.com/airlift/airline

Bonus: picocli lets you create native images using Graal, so you can really build native cli executable using Java.

Same question, but for C++?

I’ve struggled to find a well-supported command-line argument parser that supports subcommands.

argparse4j is really easy to use and feels similar to argparse in Python.