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{
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,6 +152,24 @@ var pluginsInfoCmd = &cobra.Command{
Str("output", outputPath).
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 {
query = fmt.Sprintf("/plugins/%s/info", pluginName)
res, body, err = c.MakeRequest(client.HTTPEnvelope{
@ -174,12 +200,14 @@ var pluginsInfoCmd = &cobra.Command{
fmt.Println(string(body))
}
}
}
},
}
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)