NewRunCmd creates a new run command
(f factory.Factory, globalFlags *flags.GlobalFlags, rawConfig *RawConfig)
| 46 | |
| 47 | // NewRunCmd creates a new run command |
| 48 | func NewRunCmd(f factory.Factory, globalFlags *flags.GlobalFlags, rawConfig *RawConfig) *cobra.Command { |
| 49 | cmd := &RunCmd{ |
| 50 | GlobalFlags: globalFlags, |
| 51 | Stdout: os.Stdout, |
| 52 | Stderr: os.Stderr, |
| 53 | } |
| 54 | |
| 55 | runCmd := &cobra.Command{ |
| 56 | Use: "run", |
| 57 | DisableFlagParsing: true, |
| 58 | Short: "Executes a predefined command", |
| 59 | Long: ` |
| 60 | ####################################################### |
| 61 | ##################### devspace run #################### |
| 62 | ####################################################### |
| 63 | Executes a predefined command from the devspace.yaml |
| 64 | |
| 65 | Examples: |
| 66 | devspace run mycommand --myarg 123 |
| 67 | devspace run mycommand2 1 2 3 |
| 68 | devspace --dependency my-dependency run any-command --any-command-flag |
| 69 | ####################################################### |
| 70 | `, |
| 71 | Args: cobra.MinimumNArgs(1), |
| 72 | } |
| 73 | runCmd.RunE = func(cobraCmd *cobra.Command, _ []string) error { |
| 74 | args, err := ParseArgs(runCmd, cmd.GlobalFlags, f.GetLog()) |
| 75 | if err != nil { |
| 76 | return err |
| 77 | } |
| 78 | |
| 79 | plugin.SetPluginCommand(cobraCmd, args) |
| 80 | return cmd.RunRun(f, args) |
| 81 | } |
| 82 | |
| 83 | if rawConfig != nil && rawConfig.Config != nil { |
| 84 | for _, cmd := range rawConfig.Config.Commands { |
| 85 | runCmd.AddCommand(NewSpecificRunCommand(cmd)) |
| 86 | } |
| 87 | } |
| 88 | runCmd.Flags().StringVar(&cmd.Dependency, "dependency", "", "Run a command from a specific dependency") |
| 89 | return runCmd |
| 90 | } |
| 91 | |
| 92 | // RunRun executes the functionality "devspace run" |
| 93 | func (cmd *RunCmd) RunRun(f factory.Factory, args []string) error { |
no test coverage detected