Skip to content

Commit

Permalink
feat: support to print plugin info
Browse files Browse the repository at this point in the history
  • Loading branch information
aooohan committed Dec 20, 2023
1 parent e1aed06 commit ac6d65b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function PLUGIN:PreInstall(ctx)
return {
--- Version number
version = "xxx",
--- Download URL
--- Download URL, support tar.gz tar.xz zip three formats
url = "xxx",
--- You just choose one of the checksum algorithms.
--- SHA256 checksum, first choice!
Expand Down
7 changes: 3 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ func main() {
Name: "info",
Usage: "show info of plugin",
Action: func(ctx *cli.Context) error {
args := ctx.Args()
l := args.Len()
if l < 2 {
args := ctx.Args().First()
if args == "" {
return cli.Exit("invalid arguments", 1)
}
return manager.Add(args.Get(0), args.Get(1))
return manager.Info(args)
},
},
{
Expand Down
17 changes: 17 additions & 0 deletions sdk/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,23 @@ func (m *Manager) Update(pluginName string) error {
return nil
}

func (m *Manager) Info(pluginName string) error {
sdk := m.sdkMap[pluginName]
if sdk == nil {
pterm.Println("This plugin has not been added.")
return fmt.Errorf("%s not installed", pluginName)
}
source := sdk.Plugin

pterm.Println("Plugin info:")
pterm.Println("Name ", "->", pterm.LightBlue(source.Name))
pterm.Println("Author ", "->", pterm.LightBlue(source.Author))
pterm.Println("Version ", "->", pterm.LightBlue(source.Version))
pterm.Println("Desc ", "->", pterm.LightBlue(source.Description))
pterm.Println("UpdateUrl", "->", pterm.LightBlue(source.UpdateUrl))
return nil
}

func (m *Manager) Add(pluginName, url string) error {
pterm.Printf("Adding plugin from %s...\n", url)
content, err := m.loadLuaFromFileOrUrl(url)
Expand Down

0 comments on commit ac6d65b

Please sign in to comment.