(_ *cobra.Command, plugin *plugins.LoadedPlugin, cmdInfo *plugins.PluginCommandInfo)
| 60 | } |
| 61 | |
| 62 | func createPluginCommand(_ *cobra.Command, plugin *plugins.LoadedPlugin, cmdInfo *plugins.PluginCommandInfo) *cobra.Command { |
| 63 | cmd := &cobra.Command{ |
| 64 | Use: cmdInfo.Name, |
| 65 | Short: cmdInfo.Description, |
| 66 | Long: fmt.Sprintf("%s\n\nProvided by plugin: %s v%s", cmdInfo.Description, plugin.Metadata.Name, plugin.Metadata.Version), |
| 67 | RunE: func(cmd *cobra.Command, args []string) error { |
| 68 | ctx := cmd.Context() |
| 69 | |
| 70 | // Collect all flags that were set |
| 71 | flags := make(map[string]*plugins.SimpleFlag) |
| 72 | |
| 73 | for _, flag := range cmdInfo.Flags { |
| 74 | simpleFlag := &plugins.SimpleFlag{ |
| 75 | Name: flag.Name, |
| 76 | Shorthand: flag.Shorthand, |
| 77 | Usage: flag.Description, |
| 78 | } |
| 79 | |
| 80 | switch flag.Type { |
| 81 | case stringFlagType: |
| 82 | if val, err := cmd.Flags().GetString(flag.Name); err == nil { |
| 83 | simpleFlag.Value = val |
| 84 | } |
| 85 | case boolFlagType: |
| 86 | if val, err := cmd.Flags().GetBool(flag.Name); err == nil { |
| 87 | simpleFlag.Value = strconv.FormatBool(val) |
| 88 | } |
| 89 | case intFlagType: |
| 90 | if val, err := cmd.Flags().GetInt(flag.Name); err == nil { |
| 91 | simpleFlag.Value = strconv.Itoa(val) |
| 92 | } |
| 93 | } |
| 94 | flags[flag.Name] = simpleFlag |
| 95 | } |
| 96 | |
| 97 | // instead of processing the persistent flags, we try to get them directly from viper |
| 98 | cliConfig := plugins.ChainloopConfig{ |
| 99 | ControlPlaneAPI: viper.GetString(confOptions.controlplaneAPI.viperKey), |
| 100 | ControlPlaneCA: viper.GetString(confOptions.controlplaneCA.viperKey), |
| 101 | CASAPI: viper.GetString(confOptions.CASAPI.viperKey), |
| 102 | CASCA: viper.GetString(confOptions.CASCA.viperKey), |
| 103 | Organization: viper.GetString(confOptions.organization.viperKey), |
| 104 | Token: viper.GetString(confOptions.authToken.viperKey), |
| 105 | } |
| 106 | |
| 107 | // Create platform configuration from viper |
| 108 | platformConfig := plugins.PlatformConfig{ |
| 109 | API: viper.GetString(confOptions.platformAPI.viperKey), |
| 110 | } |
| 111 | |
| 112 | // Create plugin configuration with command, arguments, and flags |
| 113 | config := plugins.PluginExecConfig{ |
| 114 | Command: cmdInfo.Name, |
| 115 | ParentCommand: cmdInfo.ParentCommand, |
| 116 | Args: args, |
| 117 | Flags: flags, |
| 118 | ChainloopConfig: cliConfig, |
| 119 | PlatformConfig: platformConfig, |
no test coverage detected