-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
90 lines (81 loc) · 2.75 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
package main
import (
"context"
"fmt"
"os"
"dokku-service/commands"
"github.com/josegonzalez/cli-skeleton/command"
"github.com/mitchellh/cli"
)
// The name of the cli tool
var AppName = "dokku-service"
// 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))
c := cli.NewCLI(AppName, Version)
c.Args = os.Args[1:]
c.Commands = command.Commands(ctx, commandMeta, Commands)
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{
"service-create": func() (cli.Command, error) {
return &commands.ServiceCreateCommand{Meta: meta, Context: ctx}, nil
},
"service-connect": func() (cli.Command, error) {
return &commands.ServiceConnectCommand{Meta: meta, Context: ctx}, nil
},
"service-destroy": func() (cli.Command, error) {
return &commands.ServiceDestroyCommand{Meta: meta, Context: ctx}, nil
},
"service-enter": func() (cli.Command, error) {
return &commands.ServiceEnterCommand{Meta: meta, Context: ctx}, nil
},
"service-export": func() (cli.Command, error) {
return &commands.ServiceExportCommand{Meta: meta, Context: ctx}, nil
},
"service-exists": func() (cli.Command, error) {
return &commands.ServiceExistsCommand{Meta: meta, Context: ctx}, nil
},
"service-import": func() (cli.Command, error) {
return &commands.ServiceImportCommand{Meta: meta, Context: ctx}, nil
},
"service-list": func() (cli.Command, error) {
return &commands.ServiceListCommand{Meta: meta, Context: ctx}, nil
},
"service-logs": func() (cli.Command, error) {
return &commands.ServiceLogsCommand{Meta: meta, Context: ctx}, nil
},
"service-pause": func() (cli.Command, error) {
return &commands.ServicePauseCommand{Meta: meta, Context: ctx}, nil
},
"service-start": func() (cli.Command, error) {
return &commands.ServiceStartCommand{Meta: meta, Context: ctx}, nil
},
"service-stop": func() (cli.Command, error) {
return &commands.ServiceStopCommand{Meta: meta, Context: ctx}, nil
},
"template-info": func() (cli.Command, error) {
return &commands.TemplateInfoCommand{Meta: meta}, nil
},
"template-list": func() (cli.Command, error) {
return &commands.TemplateListCommand{Meta: meta}, nil
},
"version": func() (cli.Command, error) {
return &command.VersionCommand{Meta: meta}, nil
},
}
}