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)
| 516 | // write `dagger call --foo=abc build` — the root command consumes the |
| 517 | // flag, and selectWith adds `with(foo: "abc")` to the query builder. |
| 518 | func (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. |
no test coverage detected