Run executes the command logic
(cobraCmd *cobra.Command, args []string, f factory.Factory, hookName string)
| 197 | |
| 198 | // Run executes the command logic |
| 199 | func (cmd *RunPipelineCmd) Run(cobraCmd *cobra.Command, args []string, f factory.Factory, hookName string) error { |
| 200 | if len(args) == 0 && cmd.Pipeline == "" { |
| 201 | return fmt.Errorf("please specify a pipeline through --pipeline or argument") |
| 202 | } else if len(args) > 0 && cmd.Pipeline == "" { |
| 203 | cmd.Pipeline = args[0] |
| 204 | args = args[1:] |
| 205 | } |
| 206 | |
| 207 | if cmd.Log == nil { |
| 208 | cmd.Log = f.GetLog() |
| 209 | } |
| 210 | if cmd.Silent { |
| 211 | cmd.Log.SetLevel(logrus.FatalLevel) |
| 212 | } |
| 213 | |
| 214 | // Print upgrade message if new version available |
| 215 | if !cmd.Render { |
| 216 | upgrade.PrintUpgradeMessage(cmd.Log) |
| 217 | } else if cmd.RenderWriter == nil { |
| 218 | cmd.RenderWriter = os.Stdout |
| 219 | } |
| 220 | |
| 221 | if cobraCmd != nil { |
| 222 | plugin.SetPluginCommand(cobraCmd, args) |
| 223 | } |
| 224 | |
| 225 | if cmd.Ctx == nil { |
| 226 | var cancelFn context.CancelFunc |
| 227 | cmd.Ctx, cancelFn = context.WithCancel(context.Background()) |
| 228 | defer cancelFn() |
| 229 | } |
| 230 | |
| 231 | // set command in context |
| 232 | if cobraCmd != nil { |
| 233 | cmd.Ctx = values.WithCommandFlags(cmd.Ctx, cobraCmd.Flags()) |
| 234 | } |
| 235 | options := cmd.BuildOptions(cmd.ToConfigOptions()) |
| 236 | ctx, err := initialize(cmd.Ctx, f, options, cmd.Log) |
| 237 | if err != nil { |
| 238 | return err |
| 239 | } |
| 240 | |
| 241 | return runWithHooks(ctx, hookName, func() error { |
| 242 | return runPipeline(ctx, args, options) |
| 243 | }) |
| 244 | } |
| 245 | |
| 246 | type CommandOptions struct { |
| 247 | flags.GlobalFlags |
no test coverage detected