RunE is the final command in the function chain, where the API request is made.
(ctx context.Context, fn *modFunction)
| 731 | |
| 732 | // RunE is the final command in the function chain, where the API request is made. |
| 733 | func (fc *FuncCommand) RunE(ctx context.Context, fn *modFunction) func(*cobra.Command, []string) error { |
| 734 | return func(cmd *cobra.Command, args []string) error { |
| 735 | q := handleObjectLeaf(fc.q, fn.ReturnType) |
| 736 | |
| 737 | // Silence usage from this point on as errors don't likely come |
| 738 | // from wrong CLI usage. |
| 739 | fc.showUsage = false |
| 740 | |
| 741 | o := cmd.OutOrStdout() |
| 742 | e := cmd.ErrOrStderr() |
| 743 | |
| 744 | // It's possible that a chain ending in an object doesn't have anything |
| 745 | // else to sub-select. In that case `q` will be nil to signal that we |
| 746 | // just want to return the object's name, without making an API request. |
| 747 | if q == nil { |
| 748 | if fn.ReturnType.Name() == "Query" { |
| 749 | return printEncodedID(o, "") |
| 750 | } |
| 751 | return handleResponse(ctx, fc.c.Dagger(), fn.ReturnType, nil, o, e, autoApply) |
| 752 | } |
| 753 | |
| 754 | var response any |
| 755 | |
| 756 | if err := makeRequest(ctx, q, &response); err != nil { |
| 757 | return err |
| 758 | } |
| 759 | |
| 760 | return handleResponse(ctx, fc.c.Dagger(), fn.ReturnType, response, o, e, autoApply) |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | func handleObjectLeaf(q *querybuilder.Selection, typeDef *modTypeDef) *querybuilder.Selection { |
| 765 | obj := typeDef.AsFunctionProvider() |
no test coverage detected