I need to start working on command line tool, and I’ve few questions
we have decided to use cobra for go https://github.com/spf13/cobra
From the help :
$ cobra help
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.
Usage:
cobra [command]
Available Commands:
add Add a command to a Cobra Application
help Help about any command
init Initialize a Cobra Application
Flags:
-a, --author string author name for copyright attribution (default "YOUR NAME")
--config string config file (default is $HOME/.cobra.yaml)
-h, --help help for cobra
-l, --license string name of license for the project
--viper use Viper for configuration (default true)
Use "cobra [command] --help" for more information about a command.
My questions are:
- what is the relations/diff between commands and flags (Available Commands) semantic ….
- is there is relations between command and flags
- Are single command should support flags
- in case in Need to provide command like deploy to x should it be ‘deploy -x’
A command tells the application what to do, for example "tool sayhello". Flags are used to pass information required by the application to achieve its task, for example "tool sayhello --message='Hello World'". Flags are often shortened by using their first letter and one hyphen.
How you design the commands and flags of your application is up to you. If you want to create a deployment tool for example, you could create a command "deploy" and a flag for the machine to deploy to: "tool deploy --machine=hostip".