-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
87 lines (77 loc) · 2.43 KB
/
Copy pathmain.go
File metadata and controls
87 lines (77 loc) · 2.43 KB
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
package main
import (
"context"
"fmt"
"os"
"github.com/dokku/docker-orchestrate/commands"
"github.com/josegonzalez/cli-skeleton/command"
"github.com/mitchellh/cli"
)
// The name of the cli tool
var AppName = "docker-orchestrate"
// Holds the version
var Version string
func main() {
os.Exit(Run(os.Args[1:]))
}
// Executes the specified subcommand
func Run(args []string) int {
ctx := context.Background()
commandMeta := command.SetupRun(ctx, AppName, Version, args)
commandMeta.Ui = command.HumanZerologUiWithFields(commandMeta.Ui, make(map[string]interface{}, 0))
cliArgs := os.Args[1:]
if len(os.Args) > 2 && os.Args[1] == "orchestrate" {
cliArgs = os.Args[2:]
}
c := cli.NewCLI(AppName, Version)
c.Args = cliArgs
c.Commands = command.Commands(ctx, commandMeta, Commands)
c.HiddenCommands = []string{"docker-cli-plugin-metadata"}
exitCode, err := c.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
return 1
}
return exitCode
}
// Returns a list of implemented commands
func Commands(ctx context.Context, meta command.Meta) map[string]cli.CommandFactory {
return map[string]cli.CommandFactory{
"cron": func() (cli.Command, error) {
return &commands.CronCommand{Meta: meta}, nil
},
"cron install": func() (cli.Command, error) {
return &commands.CronInstallCommand{Meta: meta}, nil
},
"cron notify": func() (cli.Command, error) {
return &commands.CronNotifyCommand{Meta: meta}, nil
},
"cron run": func() (cli.Command, error) {
return &commands.CronRunCommand{Meta: meta}, nil
},
"cron uninstall": func() (cli.Command, error) {
return &commands.CronUninstallCommand{Meta: meta}, nil
},
"deploy": func() (cli.Command, error) {
return &commands.DeployCommand{Meta: meta}, nil
},
"image prune": func() (cli.Command, error) {
return &commands.ImagePruneCommand{Meta: meta}, nil
},
"run execute": func() (cli.Command, error) {
return &commands.RunExecuteCommand{Meta: meta}, nil
},
"run list": func() (cli.Command, error) {
return &commands.RunListCommand{Meta: meta}, nil
},
"run list-executions": func() (cli.Command, error) {
return &commands.RunListExecutionsCommand{Meta: meta}, nil
},
"docker-cli-plugin-metadata": func() (cli.Command, error) {
return &commands.DockerCliPluginMetadataCommand{Meta: meta, Version: Version}, nil
},
"version": func() (cli.Command, error) {
return &command.VersionCommand{Meta: meta}, nil
},
}
}