-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiltctl.go
59 lines (48 loc) · 1.44 KB
/
quiltctl.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
package quiltctl
import (
"flag"
"os"
"github.com/quilt/quilt/quiltctl/command"
log "github.com/Sirupsen/logrus"
)
// Note the `minion` command is in quiltclt_posix.go as it only runs on posix systems.
var commands = map[string]command.SubCommand{
"daemon": command.NewDaemonCommand(),
"get": &command.Get{},
"inspect": &command.Inspect{},
"logs": command.NewLogCommand(),
"ps": command.NewPsCommand(),
"run": command.NewRunCommand(),
"ssh": command.NewSSHCommand(),
"stop": command.NewStopCommand(),
"version": &command.Version{},
"debug-logs": command.NewDebugCommand(),
}
// Run parses and runs the quiltctl subcommand given the command line arguments.
func Run(cmdName string, args []string) {
cmd, err := parseSubcommand(cmdName, commands[cmdName], args)
if err != nil {
log.WithError(err).Error("Unable to parse subcommand.")
os.Exit(1)
}
os.Exit(cmd.Run())
}
// HasSubcommand returns true if quiltctl has a subcommand for the given name.
func HasSubcommand(name string) bool {
_, ok := commands[name]
return ok
}
func parseSubcommand(name string, cmd command.SubCommand, args []string) (
command.SubCommand, error) {
flags := flag.NewFlagSet(name, flag.ExitOnError)
cmd.InstallFlags(flags)
if err := flags.Parse(args); err != nil {
flags.Usage()
return nil, err
}
if err := cmd.Parse(flags.Args()); err != nil {
flags.Usage()
return nil, err
}
return cmd, nil
}