cmd/cmd/example-cmd.go

40 lines
895 B
Go

package main
import (
"fmt"
"os"
"go.fifitido.net/cmd"
"go.fifitido.net/cmd/opt"
)
var (
so = opt.String("string", "s", "", "example string option")
io = opt.Int("int", "i", 0, "example int option")
fo = opt.Float("float", "f", 0, "example float option")
bo = opt.Bool("bool", "b", false, "example bool option")
)
var root = cmd.NewRoot(
"example-cmd",
cmd.WithShortDescription("Example command"),
cmd.WithLongDescription(`An example command to show how to use go.fifitido.net/cmd
this example is just a simple hello world program to show
the basics of the library.`),
cmd.WithArgument("name", false),
cmd.WithSubcommand(cmd.CompletionsSubcommand()),
cmd.WithOptions(so, io, fo, bo),
cmd.WithRunFunc(func(args []string) {
if len(args) == 0 {
fmt.Println("Hello World!")
} else {
fmt.Printf("Hello %s!\n", args[0])
}
}),
)
func main() {
root.Execute(os.Args)
}