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

Method addSubCommands

cmd/dagger/functions.go:614–645  ·  view source on GitHub ↗

addSubCommands creates sub-commands for the functions in an object or interface type definition.

(ctx context.Context, cmd *cobra.Command, typeDef *modTypeDef)

Source from the content-addressed store, hash-verified

612// addSubCommands creates sub-commands for the functions in an object or
613// interface type definition.
614func (fc *FuncCommand) addSubCommands(ctx context.Context, cmd *cobra.Command, typeDef *modTypeDef) error {
615 if err := fc.mod.LoadTypeDef(typeDef); err != nil {
616 return err
617 }
618
619 fnProvider := typeDef.AsFunctionProvider()
620 if fnProvider == nil {
621 return nil
622 }
623
624 cmd.AddGroup(funcGroup)
625
626 fns, skipped, err := GetSupportedFunctions(fnProvider)
627 if err != nil {
628 return err
629 }
630
631 for _, fn := range fns {
632 subCmd := fc.makeSubCmd(ctx, fn)
633 cmd.AddCommand(subCmd)
634 }
635
636 if cmd.HasAvailableSubCommands() {
637 cmd.Use += " <function>"
638 }
639
640 if len(skipped) > 0 {
641 cmd.Annotations[skippedCmdsAnnotation] = strings.Join(skipped, ", ")
642 }
643
644 return nil
645}
646
647// makeSubCmd creates a sub-command for a function definition.
648func (fc *FuncCommand) makeSubCmd(ctx context.Context, fn *modFunction) *cobra.Command {

Callers 1

cobraBuilderMethod · 0.95

Calls 5

makeSubCmdMethod · 0.95
GetSupportedFunctionsFunction · 0.85
LoadTypeDefMethod · 0.80
AsFunctionProviderMethod · 0.80
AddCommandMethod · 0.80

Tested by

no test coverage detected