Package command
Package command provide simple API to create modern command-line interface, mainly for lightweight usage, inspired by cobra
Usage
package main
import (
"fmt"
"os"
"github.com/chenen3/command"
)
func main() {
// Initial root command
root := &command.Command{
Name: "root", // change this to actual project name
Desc: "example description of root command",
Do: func(self *command.Command) {
self.Help()
},
}
// Add sub command
versionCmd := &command.Command{
Name: "version",
Desc: "print version",
Do: func(_ *command.Command) {
fmt.Println("version v0.1-beta")
},
}
root.AddCommand(versionCmd)
// Execute root command
err := root.Execute()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
Example output
$ go run main.go
example description of root command
Usage:
root [flags]
root [command]
Commands:
version print version
Flags:
-help
help for root
Use "root [command] --help" for more information about a command.
$ go run main.go version
version v0.1-beta