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

Method addFlagsForFunction

cmd/dagger/functions.go:572–610  ·  view source on GitHub ↗

addFlagsForFunction creates the flags for a function's arguments.

(cmd *cobra.Command, fn *modFunction)

Source from the content-addressed store, hash-verified

570
571// addFlagsForFunction creates the flags for a function's arguments.
572func (fc *FuncCommand) addFlagsForFunction(cmd *cobra.Command, fn *modFunction) error {
573 var skipped []string
574
575 var hasArgs bool
576
577 for _, arg := range fn.Args {
578 if err := fc.mod.LoadTypeDef(arg.TypeDef); err != nil {
579 return err
580 }
581
582 if err := arg.AddFlag(cmd.Flags()); err != nil {
583 var e *UnsupportedFlagError
584 if errors.As(err, &e) {
585 skipped = append(skipped, arg.FlagName())
586 continue
587 }
588 return err
589 }
590 if arg.IsRequired() {
591 cmd.MarkFlagRequired(arg.FlagName())
592 }
593 cmd.Flags().SetAnnotation(
594 arg.FlagName(),
595 "help:group",
596 []string{"Arguments"},
597 )
598 hasArgs = true
599 }
600
601 if hasArgs {
602 cmd.Use += " [arguments]"
603 }
604
605 if len(skipped) > 0 {
606 cmd.Annotations[skippedOptsAnnotation] = strings.Join(skipped, ", ")
607 }
608
609 return nil
610}
611
612// addSubCommands creates sub-commands for the functions in an object or
613// interface type definition.

Callers 1

cobraBuilderMethod · 0.95

Calls 4

LoadTypeDefMethod · 0.80
AddFlagMethod · 0.80
FlagNameMethod · 0.80
IsRequiredMethod · 0.80

Tested by

no test coverage detected