forked from AliyunContainerService/pouch
/
main.go
70 lines (61 loc) · 1.93 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
package main
import (
"fmt"
"os"
)
func main() {
cli := NewCli()
// set global flags for rootCmd in cli.
cli.SetFlags()
base := &baseCommand{cmd: cli.rootCmd, cli: cli}
// Add all subcommands.
cli.AddCommand(base, &PullCommand{})
cli.AddCommand(base, &CreateCommand{})
cli.AddCommand(base, &StartCommand{})
cli.AddCommand(base, &StopCommand{})
cli.AddCommand(base, &PsCommand{})
cli.AddCommand(base, &RmCommand{})
cli.AddCommand(base, &RestartCommand{})
cli.AddCommand(base, &ExecCommand{})
cli.AddCommand(base, &VersionCommand{})
cli.AddCommand(base, &InfoCommand{})
cli.AddCommand(base, &ImageMgmtCommand{})
cli.AddCommand(base, &ImagesCommand{})
cli.AddCommand(base, &RmiCommand{})
cli.AddCommand(base, &VolumeCommand{})
cli.AddCommand(base, &NetworkCommand{})
cli.AddCommand(base, &TagCommand{})
cli.AddCommand(base, &LoadCommand{})
cli.AddCommand(base, &InspectCommand{})
cli.AddCommand(base, &RenameCommand{})
cli.AddCommand(base, &PauseCommand{})
cli.AddCommand(base, &UnpauseCommand{})
cli.AddCommand(base, &RunCommand{})
cli.AddCommand(base, &LoginCommand{})
cli.AddCommand(base, &UpdateCommand{})
cli.AddCommand(base, &LogoutCommand{})
cli.AddCommand(base, &UpgradeCommand{})
cli.AddCommand(base, &TopCommand{})
cli.AddCommand(base, &LogsCommand{})
cli.AddCommand(base, &RemountLxcfsCommand{})
cli.AddCommand(base, &WaitCommand{})
// add generate doc command
cli.AddCommand(base, &GenDocCommand{})
if err := cli.Run(); err != nil {
// deal with ExitError, which should be recognize as error, and should
// not be exit with status 0.
if exitErr, ok := err.(ExitError); ok {
if exitErr.Status != "" {
fmt.Fprintln(os.Stderr, exitErr.Status)
}
if exitErr.Code == 0 {
// when get error with ExitError, code should not be 0.
exitErr.Code = 1
}
os.Exit(exitErr.Code)
}
// not ExitError, print error to os.Stderr, exit code 1.
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}