/
generate.go
152 lines (121 loc) · 5 KB
/
generate.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package cli
import (
"fmt"
"net/http"
"github.com/aquaproj/aqua/pkg/config"
"github.com/aquaproj/aqua/pkg/controller"
"github.com/urfave/cli/v2"
)
const generateDescription = `Search packages in registries and output the configuration interactively.
If no argument is passed, interactive fuzzy finder is launched.
$ aqua g
influxdata/influx-cli (standard) (influx) ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
newrelic/newrelic-cli (standard) (newrelic) │ cli/cli
pivotal-cf/pivnet-cli (standard) (pivnet) │
scaleway/scaleway-cli (standard) (scw) │ https://cli.github.com/
tfmigrator/cli (standard) (tfmigrator) │ GitHub’cs official command line tool
aws/copilot-cli (standard) (copilot) │
codeclimate/test-reporter (standard) │
create-go-app/cli (standard) (cgapp) │
harness/drone-cli (standard) (drone) │
sigstore/rekor (standard) (rekor-cli) │
getsentry/sentry-cli (standard) │
knative/client (standard) (kn) │
rancher/cli (standard) (rancher) │
tektoncd/cli (standard) (tkn) │
civo/cli (standard) (civo) │
dapr/cli (standard) (dapr) │
mongodb/mongocli (standard) │
openfaas/faas-cli (standard) │
> cli/cli (standard) (gh) │
48/380 │
> cli └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
Please select the package you want to install, then the package configuration is outptted.
You can select multiple packages by tab key.
Please copy and paste the outputted configuration in the aqua configuration file.
$ aqua g # tfmigrator/cli is selected
- name: tfmigrator/cli@v0.2.1
You can update the configuration file directly with "-i" option.
$ aqua g -i
You can update an imported file with "-o" option.
$ aqua g -o aqua/pkgs.yaml
You can pass packages with positional arguments.
$ aqua g [<registry name>,<package name>[@<version>] ...]
$ aqua g standard,cli/cli standard,junegunn/fzf standard,suzuki-shunsuke/tfcmt@v3.0.0
- name: cli/cli@v2.2.0
- name: junegunn/fzf@0.28.0
- name: suzuki-shunsuke/tfcmt@v3.0.0
You can omit the registry name if it is "standard".
$ aqua g cli/cli
- name: cli/cli@v2.2.0
With "-f" option, you can pass packages.
$ aqua g -f packages.txt # list of <registry name>,<package name>
- name: cli/cli@v2.2.0
- name: junegunn/fzf@0.28.0
- name: tfmigrator/cli@v0.2.1
$ cat packages.txt | aqua g -f -
- name: cli/cli@v2.2.0
- name: junegunn/fzf@0.28.0
- name: tfmigrator/cli@v0.2.1
$ aqua list | aqua g -f - # Generate configuration to install all packages
You can omit the registry name if it is "standard".
echo "cli/cli" | aqua g -f -
- name: cli/cli@v2.2.0
You can select a version interactively with "-s" option.
$ aqua g -s
The option "-pin" is useful to prevent the package from being updated by Renovate.
$ aqua g -pin cli/cli
- name: cli/cli
version: v2.2.0
`
func (runner *Runner) newGenerateCommand() *cli.Command {
return &cli.Command{
Name: "generate",
Aliases: []string{"g"},
Usage: "Search packages in registries and output the configuration interactively",
ArgsUsage: `[<registry name>,<package name> ...]`,
Description: generateDescription,
Action: runner.generateAction,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "f",
Usage: `the file path of packages list. When the value is "-", the list is passed from the standard input`,
},
&cli.BoolFlag{
Name: "i",
Usage: `Insert packages to configuration file`,
},
&cli.BoolFlag{
Name: "pin",
Usage: `Pin version`,
},
&cli.StringFlag{
Name: "o",
Usage: `inserted file`,
},
&cli.BoolFlag{
Name: "select-version",
Aliases: []string{"s"},
Usage: `Select the installed version interactively`,
},
},
}
}
func (runner *Runner) generateAction(c *cli.Context) error {
tracer, err := startTrace(c.String("trace"))
if err != nil {
return err
}
defer tracer.Stop()
cpuProfiler, err := startCPUProfile(c.String("cpu-profile"))
if err != nil {
return err
}
defer cpuProfiler.Stop()
param := &config.Param{}
if err := runner.setParam(c, "generate", param); err != nil {
return fmt.Errorf("parse the command line arguments: %w", err)
}
ctrl := controller.InitializeGenerateCommandController(c.Context, param, http.DefaultClient, runner.Runtime)
return ctrl.Generate(c.Context, runner.LogE, param, c.Args().Slice()...) //nolint:wrapcheck
}