First of all install cobra framework
go get github.com/spf13/cobra/cobra
Initialize the boilerplate
cobra init --pkg-name=github.com/danielchg/gocli
Add new option say
to our CLI
cobra add say
Add subcommand say hello
cobra add hello
and edit the content of the file cmd/hello.go
with the following in the function init
func init() {
sayCmd.AddCommand(helloCmd)
}
and also teh conten of the Run
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Hello World!")
},
go build .
./gocli say hello
Hello World!