Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(list): support outputting installed packages #2733

Merged
merged 2 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/wc-integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ jobs:
GITHUB_TOKEN: ${{steps.token.outputs.token}}

- run: aqua list
- run: aqua list -installed
- run: aqua list -installed -a

- run: aqua update-checksum
working-directory: tests/main
env:
Expand Down
23 changes: 23 additions & 0 deletions pkg/cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,30 @@ standard,99designs/aws-vault
standard,abiosoft/colima
standard,abs-lang/abs
...

If the option -installed is set, the command lists only installed packages.

$ aqua list -installed
standard,golangci/golangci-lint,v1.56.2
standard,goreleaser/goreleaser,v1.24.0
...

By default, the command doesn't list global configuration packages.
If you want to list global configuration packages too, please set the option -a.

$ aqua list -installed -a
`,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "installed",
Usage: "List installed packages",
},
&cli.BoolFlag{
Name: "all",
Aliases: []string{"a"},
Usage: "List global configuration packages too",
},
},
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/cli/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (r *Runner) setParam(c *cli.Context, commandName string, param *config.Para
param.SLSADisabled = c.Bool("disable-slsa")
param.Limit = c.Int("limit")
param.SelectVersion = c.Bool("select-version")
param.Installed = c.Bool("installed")
param.ShowVersion = c.Bool("version")
param.File = c.String("f")
if cmd := c.String("cmd"); cmd != "" {
Expand Down
1 change: 1 addition & 0 deletions pkg/config/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ type Param struct {
OnlyRegistry bool
CosignDisabled bool
SLSADisabled bool
Installed bool
PolicyConfigFilePaths []string
Commands []string
}
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/list/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package list

type ConfigFinder interface {
Find(wd, configFilePath string, globalConfigFilePaths ...string) (string, error)
Finds(wd, configFilePath string) []string
}
3 changes: 3 additions & 0 deletions pkg/controller/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
)

func (c *Controller) List(ctx context.Context, param *config.Param, logE *logrus.Entry) error { //nolint:cyclop
if param.Installed {
return c.listInstalled(param, logE)
}
cfg := &aqua.Config{}
cfgFilePath, err := c.configFinder.Find(param.PWD, param.ConfigFilePath, param.GlobalConfigFilePaths...)
if err != nil {
Expand Down
49 changes: 49 additions & 0 deletions pkg/controller/list/list_installed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package list

import (
"fmt"

"github.com/aquaproj/aqua/v2/pkg/config"
"github.com/aquaproj/aqua/v2/pkg/config/aqua"
"github.com/sirupsen/logrus"
"github.com/suzuki-shunsuke/logrus-error/logerr"
)

func (c *Controller) listInstalled(param *config.Param, logE *logrus.Entry) error {
for _, cfgFilePath := range c.configFinder.Finds(param.PWD, param.ConfigFilePath) {
if err := c.listInstalledByConfig(cfgFilePath); err != nil {
return logerr.WithFields(err, logrus.Fields{ //nolint:wrapcheck
"config_file_path": cfgFilePath,
})
}
}

if !param.All {
return nil
}

for _, cfgFilePath := range param.GlobalConfigFilePaths {
logE := logE.WithField("config_file_path", cfgFilePath)
logE.Debug("checking a global configuration file")
if _, err := c.fs.Stat(cfgFilePath); err != nil {
continue
}
if err := c.listInstalledByConfig(cfgFilePath); err != nil {
return logerr.WithFields(err, logrus.Fields{ //nolint:wrapcheck
"config_file_path": cfgFilePath,
})
}
}
return nil
}

func (c *Controller) listInstalledByConfig(cfgFilePath string) error {
cfg := &aqua.Config{}
if err := c.configReader.Read(cfgFilePath, cfg); err != nil {
return err //nolint:wrapcheck
}
for _, pkg := range cfg.Packages {
fmt.Fprintln(c.stdout, pkg.Name+"\t"+pkg.Version+"\t"+pkg.Registry)
}
return nil
}
Loading