forked from distribworks/dkron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (59 loc) · 1.39 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
// Command that implements the main executable.
package main
import (
"fmt"
"os"
"github.com/hashicorp/go-plugin"
"github.com/mitchellh/cli"
"github.com/victorcoder/dkron/dkron"
)
const (
VERSION = "0.9.6"
)
func main() {
// Get the command line args. We shortcut "--version" and "-v" to
// just show the version.
args := os.Args[1:]
for _, arg := range args {
if arg == "-v" || arg == "--version" {
newArgs := make([]string, len(args)+1)
newArgs[0] = "version"
copy(newArgs[1:], args)
args = newArgs
break
}
}
c := cli.NewCLI("dkron", VERSION)
c.Args = args
c.HelpFunc = cli.BasicHelpFunc("dkron")
ui := &cli.BasicUi{Writer: os.Stdout}
plugins := &Plugins{}
plugins.DiscoverPlugins()
// Make sure we clean up any managed plugins at the end of this
c.Commands = map[string]cli.CommandFactory{
"agent": func() (cli.Command, error) {
return &dkron.AgentCommand{
Ui: ui,
Version: VERSION,
ProcessorPlugins: plugins.Processors,
}, nil
},
"keygen": func() (cli.Command, error) {
return &dkron.KeygenCommand{
Ui: ui,
}, nil
},
"version": func() (cli.Command, error) {
return &dkron.VersionCommand{
Version: VERSION,
Ui: ui,
}, nil
},
}
exitStatus, err := c.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
}
plugin.CleanupClients()
os.Exit(exitStatus)
}