cmd
More convenient commands builder base on Cobra.
Installation
$: go get github.com/x-mod/cmd
Dependence
Quick Start
Only Root Command
package main
import (
"fmt"
"github.com/x-mod/cmd"
)
func main() {
cmd.RootMain(RootMain)
cmd.Version("specified version")
cmd.Exit(cmd.Execute())
}
func RootMain(c *cmd.Command, args []string) {
fmt.Println("my root command running ...")
}
Sub Commands
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/x-mod/cmd"
)
func main() {
cmd.Add(
cmd.Name("svc"),
cmd.Short("service short name"),
cmd.SubCommand(
cmd.NewCommand(
cmd.Name("v1"),
cmd.Short("version 1"),
cmd.Main(V1),
),
),
)
cmd.Version("version string")
cmd.Exit(cmd.Execute())
}
func V1(c *cmd.Command, args []string) {
fmt.Println("V1 called", filepath.Base(os.Args[0]))
}