addSubCommands creates sub-commands for the functions in an object or interface type definition.
(ctx context.Context, cmd *cobra.Command, typeDef *modTypeDef)
| 612 | // addSubCommands creates sub-commands for the functions in an object or |
| 613 | // interface type definition. |
| 614 | func (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. |
| 648 | func (fc *FuncCommand) makeSubCmd(ctx context.Context, fn *modFunction) *cobra.Command { |
no test coverage detected