-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
98 lines (89 loc) · 1.91 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"os"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
const usage = `mydocker is a simple container runtime implementation.
The purpose of this project is to learn how docker works and how to write a docker by ourselves
Enjoy it, just for fun.`
func main() {
app := cli.NewApp()
app.Name = "Mydocker"
app.Usage = usage
// init command params
app.Commands = []cli.Command{
initCommand,
runCommand,
commitCommand,
listCommand,
logCommand,
execCommand,
stopCommand,
removeCommand,
networkCommand,
}
// init logrus configs
app.Before = func(ctx *cli.Context) error {
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)
return nil
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
// urfaveCli-demo
func urfaveCli() {
app := cli.NewApp()
app.Name = "demo"
app.Usage = usage
// global config
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "lang, l",
Value: "english",
Usage: "Language for the greeting",
},
cli.StringFlag{
Name: "config, c",
Usage: "Load configuration from `FILE`",
},
}
// support command lists, for example go run main.go -c xxx -a xxx
app.Commands = []cli.Command{
{
Name: "complete",
Aliases: []string{"c"},
Usage: "complete one task",
Action: func(c *cli.Context) error {
log.Println("run command and complete")
for i, v := range c.Args() {
log.Printf("args i:%v v:%v\n", i, v)
}
return nil
},
},
{
Name: "add",
Aliases: []string{"a"},
Usage: "add one task",
Flags: []cli.Flag{cli.Int64Flag{
Name: "priority",
Value: 1,
Usage: "priority for current task",
}},
Action: func(c *cli.Context) error {
log.Println("run command add")
for i, v := range c.Args() {
log.Printf("args i:%v v:%v\n", i, v)
}
return nil
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}