-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
102 lines (89 loc) · 2.28 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
91
92
93
94
95
96
97
98
99
100
101
102
// Package Entrypoing into launchpad executable
package main
import (
"errors"
"fmt"
"os"
"path"
"github.com/Mirantis/launchpad/cmd"
"github.com/Mirantis/launchpad/pkg/completion"
"github.com/Mirantis/launchpad/version"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
func init() {
log.SetOutput(os.Stdout)
}
var errUnsupportedShell = errors.New("unsupported shell")
func main() {
versionCmd := &cli.Command{
Name: "version",
Action: func(_ *cli.Context) error {
fmt.Printf("version: %s\n", version.Version)
fmt.Printf("commit: %s\n", version.GitCommit)
return nil
},
}
completionCmd := &cli.Command{
Name: "completion",
Hidden: true,
Description: `Generates a shell auto-completion script.
Typical locations for the generated output are:
- Bash: /etc/bash_completion.d/launchpad
- Zsh: /usr/local/share/zsh/site-functions/_launchpad
- Fish: ~/.config/fish/completions/launchpad.fish`,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "shell",
Usage: "Shell to generate the script for",
Value: "bash",
Aliases: []string{"s"},
EnvVars: []string{"SHELL"},
},
},
Action: func(ctx *cli.Context) error {
switch path.Base(ctx.String("shell")) {
case "bash":
fmt.Print(completion.BashTemplate())
case "zsh":
fmt.Print(completion.ZshTemplate())
case "fish":
t, err := ctx.App.ToFishCompletion()
if err != nil {
return fmt.Errorf("failed to generate fish completion: %w", err)
}
fmt.Print(t)
default:
return fmt.Errorf("%w: no completion script available for %s", errUnsupportedShell, ctx.String("shell"))
}
return nil
},
}
cli.AppHelpTemplate = fmt.Sprintf(`%s
GETTING STARTED:
https://docs.mirantis.com/mke/3.7/overview.html
SUPPORT:
https://github.com/Mirantis/launchpad/issues
`, cli.AppHelpTemplate)
app := &cli.App{
Name: "launchpad",
Usage: "Mirantis Launchpad",
EnableBashCompletion: true,
Commands: []*cli.Command{
cmd.NewApplyCommand(),
cmd.RegisterCommand(),
cmd.NewDescribeCommand(),
cmd.NewClientConfigCommand(),
cmd.NewExecCommand(),
cmd.NewResetCommand(),
cmd.NewInitCommand(),
cmd.NewDownloadLaunchpadCommand(),
completionCmd,
versionCmd,
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}