selectFunc adds the function selection to the query.
(fn *modFunction, cmd *cobra.Command)
| 674 | |
| 675 | // selectFunc adds the function selection to the query. |
| 676 | func (fc *FuncCommand) selectFunc(fn *modFunction, cmd *cobra.Command) error { |
| 677 | fc.q = fc.q.Select(fn.Name) |
| 678 | |
| 679 | missingFlags := []string{} |
| 680 | |
| 681 | type flagResult struct { |
| 682 | idx int |
| 683 | flag string |
| 684 | value any |
| 685 | } |
| 686 | |
| 687 | p := pool.NewWithResults[flagResult]().WithErrors() |
| 688 | |
| 689 | for i, a := range fn.SupportedArgs() { |
| 690 | flag, err := a.GetFlag(cmd.Flags()) |
| 691 | if err != nil { |
| 692 | return err |
| 693 | } |
| 694 | |
| 695 | if !flag.Changed { |
| 696 | if a.IsRequired() { |
| 697 | missingFlags = append(missingFlags, a.FlagName()) |
| 698 | } |
| 699 | // don't send optional arguments that weren't set |
| 700 | continue |
| 701 | } |
| 702 | |
| 703 | p.Go(func() (flagResult, error) { |
| 704 | v, err := a.GetFlagValue(fc.ctx, flag, fc.c.Dagger(), fc.mod) |
| 705 | if err != nil { |
| 706 | return flagResult{}, err |
| 707 | } |
| 708 | return flagResult{i, a.Name, v}, nil |
| 709 | }) |
| 710 | } |
| 711 | |
| 712 | vals, err := p.Wait() |
| 713 | if err != nil { |
| 714 | return err |
| 715 | } |
| 716 | |
| 717 | sort.Slice(vals, func(i, j int) bool { |
| 718 | return vals[i].idx < vals[j].idx |
| 719 | }) |
| 720 | |
| 721 | for _, flag := range vals { |
| 722 | fc.q = fc.q.Arg(flag.flag, flag.value) |
| 723 | } |
| 724 | |
| 725 | if len(missingFlags) > 0 { |
| 726 | return fmt.Errorf(`required flag(s) "%s" not set`, strings.Join(missingFlags, `", "`)) |
| 727 | } |
| 728 | |
| 729 | return nil |
| 730 | } |
| 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 { |
no test coverage detected