(cmd *cobra.Command, input authoredBodyInput, required bool)
| 786 | } |
| 787 | |
| 788 | func readAuthoredBody(cmd *cobra.Command, input authoredBodyInput, required bool) (string, error) { |
| 789 | if cmd.Flags().Changed("file") && input.stdin { |
| 790 | return "", errors.New("cli: --file and --stdin cannot be combined") |
| 791 | } |
| 792 | if input.stdin { |
| 793 | body, err := io.ReadAll(cmd.InOrStdin()) |
| 794 | if err != nil { |
| 795 | return "", fmt.Errorf("cli: read authored body from stdin: %w", err) |
| 796 | } |
| 797 | return string(body), nil |
| 798 | } |
| 799 | if cmd.Flags().Changed("file") { |
| 800 | path := strings.TrimSpace(input.file) |
| 801 | if path == "" { |
| 802 | return "", errors.New("cli: --file cannot be empty") |
| 803 | } |
| 804 | body, err := os.ReadFile(path) |
| 805 | if err != nil { |
| 806 | return "", fmt.Errorf("cli: read authored body file: %w", err) |
| 807 | } |
| 808 | return string(body), nil |
| 809 | } |
| 810 | if required { |
| 811 | return "", errors.New("cli: provide authored body with --file or --stdin") |
| 812 | } |
| 813 | return "", nil |
| 814 | } |
| 815 | |
| 816 | func changedStringFlag(cmd *cobra.Command, name string, value string) (string, error) { |
| 817 | if !cmd.Flags().Changed(name) { |
no test coverage detected