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

Method makeSubCmd

cmd/dagger/functions.go:648–673  ·  view source on GitHub ↗

makeSubCmd creates a sub-command for a function definition.

(ctx context.Context, fn *modFunction)

Source from the content-addressed store, hash-verified

646
647// makeSubCmd creates a sub-command for a function definition.
648func (fc *FuncCommand) makeSubCmd(ctx context.Context, fn *modFunction) *cobra.Command {
649 newCmd := &cobra.Command{
650 Use: cliName(fn.Name),
651 Short: fn.Short(),
652 Long: fn.Description,
653 GroupID: funcGroup.ID,
654 DisableFlagsInUseLine: true,
655 // FIXME: Persistent flags should be marked as hidden for sub-commands
656 // but it's not working, so setting an annotation to circumvent it.
657 Annotations: map[string]string{
658 "help:hideInherited": "true",
659 },
660 // Using PreRunE to build the next set of flags and sub-commands.
661 // This allows us to attach a function definition to a cobra.Command,
662 // which simplifies the command tree traversal and building process.
663 PreRunE: fc.cobraBuilder(ctx, fn),
664 // This is going to be executed in the "execution" vertex, when
665 // we have the final/leaf command.
666 RunE: fc.RunE(ctx, fn),
667 }
668
669 newCmd.Flags().SetInterspersed(false)
670 newCmd.SetContext(ctx)
671
672 return newCmd
673}
674
675// selectFunc adds the function selection to the query.
676func (fc *FuncCommand) selectFunc(fn *modFunction, cmd *cobra.Command) error {

Callers 1

addSubCommandsMethod · 0.95

Calls 4

cobraBuilderMethod · 0.95
RunEMethod · 0.95
cliNameFunction · 0.85
ShortMethod · 0.65

Tested by

no test coverage detected