This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (62 loc) · 2.36 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright © 2020 Hedzr Yeh.
package main
import (
"fmt"
"github.com/hedzr/cmdr"
cmdr_examples "github.com/hedzr/cmdr-examples"
)
func main() {
Entry()
}
func Entry() {
if err := cmdr.Exec(buildRootCmd()); err != nil {
fmt.Printf("error: %+v\n", err)
}
}
func buildRootCmd() (rootCmd *cmdr.RootCommand) {
root := cmdr.Root(appName, cmdr_examples.Version).
Copyright(copyright, "hedzr").
Description(desc, longDesc).
Examples(examples)
rootCmd = root.RootCommand()
tg(root)
return
}
func tg(root cmdr.OptCmd) {
// toggle-group
c := root.NewSubCommand("toggle-group", "tg").
Description("soundex test").
Group("Test").
TailPlaceholder("[text1, text2, ...]").
Action(func(cmd *cmdr.Command, args []string) (err error) {
selectedMuxType := cmdr.GetStringR("toggle-group.mux-type")
fmt.Printf("Flag 'echo' = %v\n", cmdr.GetBoolR("toggle-group.echo"))
fmt.Printf("Flag 'gin' = %v\n", cmdr.GetBoolR("toggle-group.gin"))
fmt.Printf("Flag 'gorilla' = %v\n", cmdr.GetBoolR("toggle-group.gorilla"))
fmt.Printf("Flag 'iris' = %v\n", cmdr.GetBoolR("toggle-group.iris"))
fmt.Printf("Flag 'std' = %v\n", cmdr.GetBoolR("toggle-group.std"))
fmt.Printf("Toggle Group 'mux-type' = %v\n", selectedMuxType)
return
})
cmdr.NewBool(false).Titles("echo", "echo").Description("using 'echo' mux").ToggleGroup("mux-type").Group("Mux").AttachTo(c)
cmdr.NewBool(false).Titles("gin", "gin").Description("using 'gin' mux").ToggleGroup("mux-type").Group("Mux").AttachTo(c)
cmdr.NewBool(false).Titles("gorilla", "gorilla").Description("using 'gorilla' mux").ToggleGroup("mux-type").Group("Mux").AttachTo(c)
cmdr.NewBool(true).Titles("iris", "iris").Description("using 'iris' mux").ToggleGroup("mux-type").Group("Mux").AttachTo(c)
cmdr.NewBool(false).Titles("std", "std").Description("using standardlib http mux mux").ToggleGroup("mux-type").Group("Mux").AttachTo(c)
}
const (
appName = "toggle-group"
copyright = "toggle-group is an effective devops tool"
desc = "toggle-group is an effective devops tool. It make an demo application for `cmdr`."
longDesc = "toggle-group is an effective devops tool. It make an demo application for `cmdr`."
examples = `
$ {{.AppName}} gen shell [--bash|--zsh|--auto]
generate bash/shell completion scripts
$ {{.AppName}} gen man
generate linux man page 1
$ {{.AppName}} --help
show help screen.
`
overview = ``
zero = 0
)