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

@ -125,12 +125,20 @@ 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,6 +152,24 @@ var pluginsInfoCmd = &cobra.Command{
Str("output", outputPath). Str("output", outputPath).
Send() Send()
if local {
var (
plugins []map[string]any
plugin makeshift.Plugin
err error
)
for _, path := range args {
plugin, err = service.LoadPluginFromFile(path)
if err != nil {
log.Error().Err(err).
Str("path", path).
Msg("failed to load plugin from path")
continue
}
plugins = append(plugins, makeshift.PluginToMap(plugin))
}
log.Info().Any("plugins", plugins).Send()
} else {
for _, pluginName := range args { for _, pluginName := range args {
query = fmt.Sprintf("/plugins/%s/info", pluginName) query = fmt.Sprintf("/plugins/%s/info", pluginName)
res, body, err = c.MakeRequest(client.HTTPEnvelope{ res, body, err = c.MakeRequest(client.HTTPEnvelope{
@ -174,12 +200,14 @@ var pluginsInfoCmd = &cobra.Command{
fmt.Println(string(body)) fmt.Println(string(body))
} }
} }
}
}, },
} }
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)