-
Notifications
You must be signed in to change notification settings - Fork 0
/
flygoctl.go
106 lines (99 loc) · 1.87 KB
/
flygoctl.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"log"
"os"
"sort"
"github.com/urfave/cli"
)
func main() {
var language string
app := cli.NewApp()
app.Name = "CtlTest"
app.Usage = "hello world"
app.Version = "0.0.1"
app.Flags = []cli.Flag{
cli.IntFlag{
Name: "port, p",
Value: 8000,
Usage: "listening port",
},
cli.StringFlag{
Name: "lang, l",
Value: "english",
Usage: "read from `FILE`",
Destination: &language,
},
}
app.Commands = []cli.Command{
{
Name: "add",
Aliases: []string{"a"},
Usage: "calc 1+1",
Category: "arithmetic",
Action: func(c *cli.Context) error {
fmt.Println("1 + 1 = ", 1+1)
return nil
},
},
{
Name: "sub",
Aliases: []string{"s"},
Usage: "calc 5-3",
Category: "arithmetic",
Action: func(c *cli.Context) error {
fmt.Println("5 - 3 = ", 5-3)
return nil
},
},
{
Name: "db",
Usage: "database operations",
Category: "database",
Subcommands: []cli.Command{
{
Name: "insert",
Usage: "insert data",
Action: func(c *cli.Context) error {
fmt.Println("insert subcommand")
return nil
},
},
{
Name: "delete",
Usage: "delete data",
Action: func(c *cli.Context) error {
fmt.Println("delete subcommand")
return nil
},
},
},
},
}
app.Action = func(c *cli.Context) error {
fmt.Println("BOOM!")
return nil
}
app.Before = func(c *cli.Context) error {
fmt.Println("app Before")
return nil
}
app.After = func(c *cli.Context) error {
fmt.Println("app After")
return nil
}
sort.Sort(cli.FlagsByName(app.Flags))
cli.HelpFlag = cli.BoolFlag{
Name: "help, h",
Usage: "Help!Help!",
}
cli.VersionFlag = cli.BoolFlag{
Name: "print-version, v",
Usage: "print version",
}
err := app.Run(os.Args)
if err != nil {
fmt.Println(err)
log.Fatal(err)
}
}