Using Cobra for advanced CLI applications
Cobra is a set of packages that allows a developer to create more complex CLI applications. This becomes more useful than just the standard flag
package when the complexity of an application causes a list of flags to become numerous.
In this section, we will talk about how to use Cobra to create structured CLI applications that are friendly to developers to add features and allow users to understand what is available in an application.
A few features that Cobra provides are as follows:
- Nested subcommands
- Command suggestions
- Aliases for commands so that you can make changes without breaking users
- Generation of help text from flags and commands
- Generation of autocompletion for various shells
- Man page creation
This section will borrow heavily from the Cobra documentation, which you can find here: https://github.com/spf13/cobra/blob/master/user_guide.md.
Code organization
To make effective use of...