Skip to content

Commit

Permalink
feat(generate): enable to add packages to a global configuration file (
Browse files Browse the repository at this point in the history
…#2804)

* feat(generate): enable to add packages to a global configuration file

* feat(generate): update the help message

* fix(generate): fix finding a configuration file

* fix(generate): fix lint errors

* ci: add an integration test
  • Loading branch information
suzuki-shunsuke committed Apr 5, 2024
1 parent f0bfd95 commit 87cf6dc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/wc-integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ jobs:
run: aqua g --pin cli/cli suzuki-shunsuke/tfcmt@v2.0.0
env:
GITHUB_TOKEN: ${{steps.token.outputs.token}}
- name: Test g -g
run: aqua g -g cli/cli
env:
GITHUB_TOKEN: ${{steps.token.outputs.token}}

- name: Test version_prefix
run: aqua -c aqua.yaml g -i kubernetes-sigs/kustomize
Expand Down
12 changes: 12 additions & 0 deletions pkg/cli/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ $ aqua g -detail cli/cli
- name: cli/cli@v2.2.0
description: GitHub’s official command line tool
link: https://github.com/cli/cli
With -g option, aqua reads a first global configuration file.
$ aqua g -g cli/cli
You can add packages to a first global configuration file with -g and -i option.
$ aqua g -g -i cli/cli
`

func (r *Runner) newGenerateCommand() *cli.Command {
Expand All @@ -131,6 +139,10 @@ func (r *Runner) newGenerateCommand() *cli.Command {
Name: "pin",
Usage: `Pin version`,
},
&cli.BoolFlag{
Name: "g",
Usage: `Insert packages in a global configuration file`,
},
&cli.BoolFlag{
Name: "detail",
Aliases: []string{"d"},
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (r *Runner) setParam(c *cli.Context, commandName string, param *config.Para
param.Insert = c.Bool("i")
}
param.All = c.Bool("all")
param.Global = c.Bool("g")
param.Detail = c.Bool("detail")
param.Prune = c.Bool("prune")
param.CosignDisabled = c.Bool("disable-cosign")
Expand Down
1 change: 1 addition & 0 deletions pkg/config/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ type Param struct {
DisableLazyInstall bool
OnlyLink bool
All bool
Global bool
Insert bool
SelectVersion bool
ShowVersion bool
Expand Down
14 changes: 12 additions & 2 deletions pkg/controller/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func (c *Controller) Generate(ctx context.Context, logE *logrus.Entry, param *co
// merge version with package name
// set default value
// Output to Stdout or Update aqua.yaml (-i)
cfgFilePath, err := c.configFinder.Find(param.PWD, param.ConfigFilePath, param.GlobalConfigFilePaths...)
cfgFilePath, err := c.getConfigFile(param)
if err != nil {
return err //nolint:wrapcheck
return err
}

cfg := &aqua.Config{}
Expand All @@ -61,6 +61,16 @@ func (c *Controller) Generate(ctx context.Context, logE *logrus.Entry, param *co
})
}

func (c *Controller) getConfigFile(param *config.Param) (string, error) {
if param.ConfigFilePath != "" || !param.Global {
return c.configFinder.Find(param.PWD, param.ConfigFilePath, param.GlobalConfigFilePaths...) //nolint:wrapcheck
}
if len(param.GlobalConfigFilePaths) == 0 {
return "", errors.New("no global configuration file is found")
}
return param.GlobalConfigFilePaths[0], nil
}

func (c *Controller) listPkgs(ctx context.Context, logE *logrus.Entry, param *config.Param, cfg *aqua.Config, cfgFilePath string, args ...string) ([]*aqua.Package, error) {
var checksums *checksum.Checksums
if cfg.ChecksumEnabled() {
Expand Down

0 comments on commit 87cf6dc

Please sign in to comment.