54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"go.fifitido.net/cmd"
|
|
"go.fifitido.net/cmd/opts"
|
|
)
|
|
|
|
var stringOpt = opts.String("string", "s", "", "example string option")
|
|
var intOpt = opts.Int("int", "i", 0, "example int option")
|
|
var boolOpt = opts.Bool("bool", "b", false, "example bool option")
|
|
var floatOpt = opts.Float("float", "f", 0, "example float option")
|
|
|
|
var root = cmd.NewRoot(
|
|
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.WithSubcommand(subcmd),
|
|
cmd.WithArgument("name", false),
|
|
cmd.WithOptions(stringOpt, intOpt, boolOpt, floatOpt),
|
|
cmd.WithRunFunc(func(args []string) {
|
|
if len(args) == 0 {
|
|
fmt.Println("Hello World!")
|
|
} else {
|
|
fmt.Printf("Hello %s!\n", args[0])
|
|
}
|
|
}),
|
|
)
|
|
|
|
var subcmd = cmd.New(
|
|
"test",
|
|
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.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)
|
|
}
|