feat (plugin): add list and info command for plugin (#1452)

Co-authored-by: Teppei Fukuda <knqyf263@gmail.com>
This commit is contained in:
Owen Rumney
2021-12-15 20:36:08 +00:00
committed by GitHub
parent a2199bb417
commit 8b5796f770
4 changed files with 135 additions and 0 deletions

View File

@@ -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 {