/
main.go
52 lines (42 loc) · 1.29 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"github.com/gookit/gcli/v3"
"github.com/gookit/goutil/dump"
)
var opts = struct {
fontName string
visualMode bool
list bool
sample bool
number int
}{}
// test run:
// go build ./_examples/simpleone && ./simpleone -h
// test run:
// go run ./_examples/simpleone
func main() {
cmd := gcli.Command{
Name: "test",
Aliases: []string{"ts"},
Desc: "this is a description <info>message</> for {$cmd}", // // {$cmd} will be replace to 'test'
}
cmd.BoolOpt(&opts.visualMode, "visual", "v", false, "Prints the font name.")
cmd.StrOpt(&opts.fontName, "font", "fn", "", "Choose a font name. Default is a random name;true")
cmd.BoolOpt(&opts.list, "list", "", false, "Lists all available fonts.")
cmd.BoolOpt(&opts.sample, "sample", "", false, "Prints a sample with that font.\nmessage at new line")
cmd.IntOpt(&opts.number, "number", "n,num", 0, "a integer option")
cmd.AddArg("arg1", "this is a argument")
cmd.AddArg("arg2", "this is a argument2")
cmd.WithConfigFn(func(opt *gcli.FlagsConfig) {
opt.DescNewline = true
})
cmd.Func = func(c *gcli.Command, args []string) error {
c.Infoln("hello, in the alone command:", c.Name)
dump.Print(args)
dump.Print(opts)
return nil
}
// Alone Running
cmd.MustRun(nil)
// cmd.Run(os.Args[1:])
}