ValidateFileFlag checks mutual exclusion rules for the --file flag. Returns nil if file is empty (flag not provided).
(file, params, data, outputPath string, pageAll bool, httpMethod string)
| 36 | // ValidateFileFlag checks mutual exclusion rules for the --file flag. |
| 37 | // Returns nil if file is empty (flag not provided). |
| 38 | func ValidateFileFlag(file, params, data, outputPath string, pageAll bool, httpMethod string) error { |
| 39 | if file == "" { |
| 40 | return nil |
| 41 | } |
| 42 | |
| 43 | _, filePath, isStdin := ParseFileFlag(file, "file") |
| 44 | if !isStdin && filePath == "" { |
| 45 | return errs.NewValidationError(errs.SubtypeInvalidArgument, "--file: empty file path"). |
| 46 | WithParam("--file") |
| 47 | } |
| 48 | |
| 49 | if outputPath != "" { |
| 50 | return errs.NewValidationError(errs.SubtypeInvalidArgument, "--file and --output are mutually exclusive").WithParams( |
| 51 | errs.InvalidParam{Name: "--file", Reason: "mutually exclusive with --output"}, |
| 52 | errs.InvalidParam{Name: "--output", Reason: "mutually exclusive with --file"}, |
| 53 | ) |
| 54 | } |
| 55 | if pageAll { |
| 56 | return errs.NewValidationError(errs.SubtypeInvalidArgument, "--file and --page-all are mutually exclusive").WithParams( |
| 57 | errs.InvalidParam{Name: "--file", Reason: "mutually exclusive with --page-all"}, |
| 58 | errs.InvalidParam{Name: "--page-all", Reason: "mutually exclusive with --file"}, |
| 59 | ) |
| 60 | } |
| 61 | if isStdin && data == "-" { |
| 62 | return errs.NewValidationError(errs.SubtypeInvalidArgument, "--file and --data cannot both read from stdin").WithParams( |
| 63 | errs.InvalidParam{Name: "--file", Reason: "only one flag may read from stdin"}, |
| 64 | errs.InvalidParam{Name: "--data", Reason: "only one flag may read from stdin"}, |
| 65 | ) |
| 66 | } |
| 67 | if isStdin && params == "-" { |
| 68 | return errs.NewValidationError(errs.SubtypeInvalidArgument, "--file and --params cannot both read from stdin").WithParams( |
| 69 | errs.InvalidParam{Name: "--file", Reason: "only one flag may read from stdin"}, |
| 70 | errs.InvalidParam{Name: "--params", Reason: "only one flag may read from stdin"}, |
| 71 | ) |
| 72 | } |
| 73 | |
| 74 | switch httpMethod { |
| 75 | case "POST", "PUT", "PATCH", "DELETE": |
| 76 | default: |
| 77 | return errs.NewValidationError(errs.SubtypeInvalidArgument, "--file requires POST, PUT, PATCH, or DELETE method"). |
| 78 | WithParam("--file"). |
| 79 | WithHint("file upload only applies to write methods; remove --file for read methods") |
| 80 | } |
| 81 | |
| 82 | return nil |
| 83 | } |
| 84 | |
| 85 | // FileUploadMeta holds file upload metadata for dry-run display. |
| 86 | // Returned by request builders when dry-run mode skips actual file reading. |