feat: implemented local plugins info

This commit is contained in:
David Allen 2025-08-31 11:01:43 -06:00
parent fa8ef7ab4b
commit e115319913
Signed by: towk
GPG key ID: 0430CDBE22619155

View file

@ -124,13 +124,21 @@ var pluginsInspectCmd = &cobra.Command{
} }
var pluginsInfoCmd = &cobra.Command{ var pluginsInfoCmd = &cobra.Command{
Use: "info", Use: "info",
Example: `
# show information of a remote plugin
makeshift plugins info jinja2 smd
# show information of a local plugin
makeshift plugins info --local $MAKESHIFT_ROOT/plugins/jinja2.so
`,
Short: "Show plugin information", Short: "Show plugin information",
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
var ( var (
host, _ = cmd.Flags().GetString("host") host, _ = cmd.Flags().GetString("host")
outputPath, _ = cmd.Flags().GetString("output") outputPath, _ = cmd.Flags().GetString("output")
local, _ = cmd.Flags().GetBool("local")
c = client.New(host) c = client.New(host)
res *http.Response res *http.Response
@ -144,34 +152,53 @@ var pluginsInfoCmd = &cobra.Command{
Str("output", outputPath). Str("output", outputPath).
Send() Send()
for _, pluginName := range args { if local {
query = fmt.Sprintf("/plugins/%s/info", pluginName) var (
res, body, err = c.MakeRequest(client.HTTPEnvelope{ plugins []map[string]any
Path: query, plugin makeshift.Plugin
Method: http.MethodGet, err error
}) )
if err != nil { for _, path := range args {
log.Error().Err(err). plugin, err = service.LoadPluginFromFile(path)
Str("host", host). if err != nil {
Str("query", query). log.Error().Err(err).
Msg("failed to make request") Str("path", path).
os.Exit(1) Msg("failed to load plugin from path")
continue
}
plugins = append(plugins, makeshift.PluginToMap(plugin))
} }
if res.StatusCode != http.StatusOK { log.Info().Any("plugins", plugins).Send()
log.Error(). } else {
Any("status", map[string]any{ for _, pluginName := range args {
"code": res.StatusCode, query = fmt.Sprintf("/plugins/%s/info", pluginName)
"message": res.Status, res, body, err = c.MakeRequest(client.HTTPEnvelope{
"body": string(body), Path: query,
}). Method: http.MethodGet,
Str("host", host). })
Msg("response returned bad status") if err != nil {
os.Exit(1) log.Error().Err(err).
} Str("host", host).
if outputPath != "" { Str("query", query).
writeFiles(outputPath, body) Msg("failed to make request")
} else { os.Exit(1)
fmt.Println(string(body)) }
if res.StatusCode != http.StatusOK {
log.Error().
Any("status", map[string]any{
"code": res.StatusCode,
"message": res.Status,
"body": string(body),
}).
Str("host", host).
Msg("response returned bad status")
os.Exit(1)
}
if outputPath != "" {
writeFiles(outputPath, body)
} else {
fmt.Println(string(body))
}
} }
} }
}, },
@ -180,6 +207,7 @@ var pluginsInfoCmd = &cobra.Command{
func init() { func init() {
pluginsCompileCmd.Flags().StringP("output", "o", "", "Set the path to save compiled plugin (matches source type, i.e. uses files or directory)") pluginsCompileCmd.Flags().StringP("output", "o", "", "Set the path to save compiled plugin (matches source type, i.e. uses files or directory)")
pluginsInfoCmd.Flags().String("host", "http://localhost:5050", "Set the makeshift remote host (can be set with MAKESHIFT_HOST)") pluginsInfoCmd.Flags().String("host", "http://localhost:5050", "Set the makeshift remote host (can be set with MAKESHIFT_HOST)")
pluginsInfoCmd.Flags().Bool("local", false, "Set whether to display information of a local plugin")
pluginsCmd.AddCommand(pluginsCompileCmd, pluginsInspectCmd, pluginsInfoCmd) pluginsCmd.AddCommand(pluginsCompileCmd, pluginsInspectCmd, pluginsInfoCmd)
rootCmd.AddCommand(pluginsCmd) rootCmd.AddCommand(pluginsCmd)