execute runs the main logic for the top level command's RunE function.
(c *cobra.Command, a []string)
| 287 | |
| 288 | // execute runs the main logic for the top level command's RunE function. |
| 289 | func (fc *FuncCommand) execute(c *cobra.Command, a []string) (rerr error) { |
| 290 | ctx := c.Context() |
| 291 | |
| 292 | var cmd *cobra.Command |
| 293 | defer func() { |
| 294 | if cmd == nil { // errored during loading |
| 295 | cmd = c |
| 296 | } |
| 297 | if ctx.Err() != nil { |
| 298 | cmd.PrintErrln("Canceled.") |
| 299 | } else if rerr != nil { |
| 300 | cmd.PrintErrln(cmd.ErrPrefix(), rerr.Error()) |
| 301 | |
| 302 | if fc.needsHelp { |
| 303 | cmd.Println() |
| 304 | // Explicitly show the help here while still returning the error. |
| 305 | // This handles the case of `dagger call --help` run on a broken module; in that case |
| 306 | // we want to error out since we can't actually load the module and show all subcommands |
| 307 | // and flags in the help output, but we still want to show the user *something* |
| 308 | fc.Help(cmd) |
| 309 | return |
| 310 | } |
| 311 | |
| 312 | if fc.showUsage { |
| 313 | cmd.PrintErrf("Run '%v --help' for usage.\n", cmd.CommandPath()) |
| 314 | } |
| 315 | } |
| 316 | }() |
| 317 | |
| 318 | var mod *moduleDef |
| 319 | var err error |
| 320 | if fc.DisableModuleLoad || moduleNoURL { |
| 321 | mod, err = initializeCore(ctx, fc.c.Dagger()) |
| 322 | } else { |
| 323 | // -m modules are loaded at engine connect time as extra modules. |
| 324 | mod, err = initializeWorkspace(ctx, fc.c.Dagger(), loadTypeDefsOpts{HideCore: true}) |
| 325 | } |
| 326 | if err != nil { |
| 327 | return err |
| 328 | } |
| 329 | fc.mod = mod |
| 330 | |
| 331 | // Now that the module is loaded, show usage by default since errors |
| 332 | // are more likely to be from wrong CLI usage. |
| 333 | fc.showUsage = true |
| 334 | |
| 335 | cmd, flags, err := fc.loadCommand(c, a) |
| 336 | if err != nil { |
| 337 | return err |
| 338 | } |
| 339 | |
| 340 | if fc.needsHelp { |
| 341 | return fc.Help(cmd) |
| 342 | } |
| 343 | |
| 344 | // No args to the parent command |
| 345 | if cmd == c { |
| 346 | return fc.RunE(ctx, fc.mod.MainObject.AsObject.Constructor)(cmd, flags) |
no test coverage detected