mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-22 23:26:39 -08:00
feat (plugin): add list and info command for plugin (#1452)
Co-authored-by: Teppei Fukuda <knqyf263@gmail.com>
This commit is contained in:
@@ -2,6 +2,8 @@ package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"golang.org/x/xerrors"
|
||||
@@ -47,6 +49,47 @@ func Uninstall(c *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Information displays information about the plugin
|
||||
func Information(c *cli.Context) error {
|
||||
if c.NArg() != 1 {
|
||||
cli.ShowSubcommandHelpAndExit(c, 1)
|
||||
}
|
||||
|
||||
if err := initLogger(c); err != nil {
|
||||
return xerrors.Errorf("initialize logger error: %w", err)
|
||||
}
|
||||
|
||||
pluginName := c.Args().First()
|
||||
info, err := plugin.Information(pluginName)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("plugin information display error: %w", err)
|
||||
}
|
||||
|
||||
if _, err = fmt.Fprintf(os.Stdout, info); err != nil {
|
||||
return xerrors.Errorf("print error: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// List displays a list of all of installed plugins
|
||||
func List(c *cli.Context) error {
|
||||
if err := initLogger(c); err != nil {
|
||||
return xerrors.Errorf("initialize error: %w", err)
|
||||
}
|
||||
|
||||
info, err := plugin.List()
|
||||
if err != nil {
|
||||
return xerrors.Errorf("plugin list display error: %w", err)
|
||||
}
|
||||
|
||||
if _, err = fmt.Fprintf(os.Stdout, info); err != nil {
|
||||
return xerrors.Errorf("print error: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run runs the plugin
|
||||
func Run(c *cli.Context) error {
|
||||
if c.NArg() < 1 {
|
||||
|
||||
Reference in New Issue
Block a user