-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(list): support outputting installed packages (#2733)
* feat(list): support outputting installed packages * feat(list): change the order and separator
- Loading branch information
1 parent
4041db9
commit 4df269e
Showing
7 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |