MCPcopy Index your code
hub / github.com/dagger/dagger / addConstructorLocalFlags

Method addConstructorLocalFlags

cmd/dagger/functions.go:518–545  ·  view source on GitHub ↗

addConstructorLocalFlags looks for a `with` field on the Query root and registers its args as local flags on the root command. This lets users write `dagger call --foo=abc build` — the root command consumes the flag, and selectWith adds `with(foo: "abc")` to the query builder.

(cmd *cobra.Command, rootType *modTypeDef)

Source from the content-addressed store, hash-verified

516// write `dagger call --foo=abc build` — the root command consumes the
517// flag, and selectWith adds `with(foo: "abc")` to the query builder.
518func (fc *FuncCommand) addConstructorLocalFlags(cmd *cobra.Command, rootType *modTypeDef) {
519 fp := rootType.AsFunctionProvider()
520 if fp == nil {
521 return
522 }
523 for _, fn := range fp.GetFunctions() {
524 if fn.Name != "with" {
525 continue
526 }
527 // Found the `with` field — register its args as local flags.
528 fc.withFn = fn
529 for _, arg := range fn.SupportedArgs() {
530 if cmd.Flags().Lookup(arg.FlagName()) != nil {
531 continue // already registered
532 }
533 fc.mod.LoadTypeDef(arg.TypeDef)
534 if err := arg.AddFlag(cmd.Flags()); err != nil {
535 continue // skip unsupported flags
536 }
537 cmd.Flags().SetAnnotation(
538 arg.FlagName(),
539 "help:group",
540 []string{"Arguments"},
541 )
542 }
543 break
544 }
545}
546
547// selectWith adds a `with(args...)` selection to the query builder if any
548// constructor flags were set.

Callers 1

cobraBuilderMethod · 0.95

Calls 7

AsFunctionProviderMethod · 0.80
SupportedArgsMethod · 0.80
FlagNameMethod · 0.80
LoadTypeDefMethod · 0.80
AddFlagMethod · 0.80
GetFunctionsMethod · 0.65
LookupMethod · 0.45

Tested by

no test coverage detected