MCPcopy Create free account
hub / github.com/dagger/dagger / execute

Method execute

cmd/dagger/functions.go:289–350  ·  view source on GitHub ↗

execute runs the main logic for the top level command's RunE function.

(c *cobra.Command, a []string)

Source from the content-addressed store, hash-verified

287
288// execute runs the main logic for the top level command's RunE function.
289func (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)

Callers 5

CommandMethod · 0.95
TestClass · 0.45
CacheVolumeClass · 0.45
TestFooerClass · 0.45
JSONValueClass · 0.45

Calls 9

HelpMethod · 0.95
loadCommandMethod · 0.95
RunEMethod · 0.95
initializeCoreFunction · 0.85
initializeWorkspaceFunction · 0.85
DaggerMethod · 0.80
ContextMethod · 0.65
ErrMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected