makeSubCmd creates a sub-command for a function definition.
(ctx context.Context, fn *modFunction)
| 646 | |
| 647 | // makeSubCmd creates a sub-command for a function definition. |
| 648 | func (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. |
| 676 | func (fc *FuncCommand) selectFunc(fn *modFunction, cmd *cobra.Command) error { |
no test coverage detected