6 ms·
Since everyone else is throwing out recommendations I personally think https://github.com/spf13/cobra https://github.com/spf13/cobra is the best CLI templating
by dashwav 6y ago
Since everyone else is throwing out recommendations I personally think https://github.com/spf13/cobra https://github.com/spf13/cobra is the best CLI templating system, especially because of how well it pairs with https://github.com/spf13/viper 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)
- Thorentis 6y agoGreat stuff! Does anything like Cobra exist for Java?
- bingo_cannon 6y agoAbsolutely! 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/ https://picocli.info/ 2: https://github.com/airlift/airline https://github.com/airlift/airline Bonus: picocli lets you create native images using Graal, so you can really build native cli executable using Java.
- pansa2 6y agoSame question, but for C++? I’ve struggled to find a well-supported command-line argument parser that supports subcommands.
- brown9-2 6y agoargparse4j is really easy to use and feels similar to argparse in Python.
- deleted 6y ago[deleted]
- sagichmal 6y agoCobra 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 https://pkg.go.dev/github.com/peterbourgon/ff/v3/ffcli is one that I've been using recently, which has been a lot nicer.
- martinni 6y agoDon'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.