From e115319913b77a57392b5f2a536ae657fc4c0687 Mon Sep 17 00:00:00 2001 From: David Allen Date: Sun, 31 Aug 2025 11:01:43 -0600 Subject: [PATCH] feat: implemented local plugins info --- cmd/plugins.go | 84 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 28 deletions(-) diff --git a/cmd/plugins.go b/cmd/plugins.go index 8917b1c..15043f0 100644 --- a/cmd/plugins.go +++ b/cmd/plugins.go @@ -124,13 +124,21 @@ var pluginsInspectCmd = &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", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { var ( host, _ = cmd.Flags().GetString("host") outputPath, _ = cmd.Flags().GetString("output") + local, _ = cmd.Flags().GetBool("local") c = client.New(host) res *http.Response @@ -144,34 +152,53 @@ var pluginsInfoCmd = &cobra.Command{ Str("output", outputPath). Send() - for _, pluginName := range args { - query = fmt.Sprintf("/plugins/%s/info", pluginName) - res, body, err = c.MakeRequest(client.HTTPEnvelope{ - Path: query, - Method: http.MethodGet, - }) - if err != nil { - log.Error().Err(err). - Str("host", host). - Str("query", query). - Msg("failed to make request") - os.Exit(1) + 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)) } - 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)) + log.Info().Any("plugins", plugins).Send() + } else { + for _, pluginName := range args { + query = fmt.Sprintf("/plugins/%s/info", pluginName) + res, body, err = c.MakeRequest(client.HTTPEnvelope{ + Path: query, + Method: http.MethodGet, + }) + if err != nil { + log.Error().Err(err). + Str("host", host). + Str("query", query). + Msg("failed to make request") + os.Exit(1) + } + 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() { 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().Bool("local", false, "Set whether to display information of a local plugin") pluginsCmd.AddCommand(pluginsCompileCmd, pluginsInspectCmd, pluginsInfoCmd) rootCmd.AddCommand(pluginsCmd)