-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
runner.go
79 lines (73 loc) · 1.6 KB
/
runner.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
package cli
import (
"context"
"io"
"time"
"github.com/urfave/cli/v2"
)
type Runner struct {
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
LDFlags *LDFlags
}
type LDFlags struct {
Version string
Commit string
Date string
}
func (runner *Runner) Run(ctx context.Context, args ...string) error {
compiledDate, err := time.Parse(time.RFC3339, runner.LDFlags.Date)
if err != nil {
compiledDate = time.Now()
}
app := cli.App{
Name: "aqua",
Usage: "General version manager. https://github.com/suzuki-shunsuke/aqua",
Version: runner.LDFlags.Version + " (" + runner.LDFlags.Commit + ")",
Compiled: compiledDate,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Usage: "log level",
EnvVars: []string{"AQUA_LOG_LEVEL"},
},
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "configuration file path",
EnvVars: []string{"AQUA_CONFIG"},
},
},
Commands: []*cli.Command{
{
Name: "install",
Aliases: []string{"i"},
Usage: "Install tools",
Action: runner.installAction,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "only-link",
Usage: "create links but skip download packages",
},
},
},
{
Name: "exec",
Usage: "Execute tool",
Action: runner.execAction,
},
{
Name: "get-bin-dir",
Usage: "Show the path where the packages are installed",
Action: runner.getBinDirAction,
},
{
Name: "version",
Usage: "Show version",
Action: runner.versionAction,
},
},
}
return app.RunContext(ctx, args) //nolint:wrapcheck
}