From d2fcf10f0309627cacea7329232f0e93fcdcf04e Mon Sep 17 00:00:00 2001 From: David Allen Date: Wed, 26 Jun 2024 13:42:24 -0600 Subject: [PATCH] Added command to inspect generator plugins --- cmd/inspect.go | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 cmd/inspect.go diff --git a/cmd/inspect.go b/cmd/inspect.go new file mode 100644 index 0000000..e94906c --- /dev/null +++ b/cmd/inspect.go @@ -0,0 +1,64 @@ +package cmd + +import ( + "fmt" + "maps" + "strings" + + "github.com/OpenCHAMI/configurator/internal/generator" + "github.com/spf13/cobra" +) + +var ( + pluginDirs []string + generators map[string]generator.Generator +) + +var inspectCmd = &cobra.Command{ + Use: "inspect", + Short: "Inspect generator plugin information", + Run: func(cmd *cobra.Command, args []string) { + // load specific plugins from positional args + generators = make(map[string]generator.Generator) + for _, path := range args { + gen, err := generator.LoadPlugin(path) + if err != nil { + fmt.Printf("failed to load plugin at path '%s': %v\n", path, err) + continue + } + generators[path] = gen + } + + // load plugins and print all plugin details + if len(pluginDirs) > 0 { + + } else { + for _, pluginDir := range config.PluginDirs { + gens, err := generator.LoadPlugins(pluginDir) + if err != nil { + fmt.Printf("failed to load plugin: %v\n", err) + continue + } + maps.Copy(generators, gens) + } + } + + // print all generator information + const WIDTH = 40 + if len(generators) > 0 { + o := "" + for _, g := range generators { + o += fmt.Sprintf("- Name: %s\n", g.GetName()) + o += fmt.Sprintf(" Version: %s\n", g.GetVersion()) + o += fmt.Sprintf(" Description: %s\n", g.GetDescription()) + o += "\n" + } + o = strings.TrimRight(o, "\n") + fmt.Printf("%s", o) + } + }, +} + +func init() { + rootCmd.AddCommand(inspectCmd) +}