MCPcopy
hub / github.com/larksuite/cli / ValidateFileFlag

Function ValidateFileFlag

internal/cmdutil/fileupload.go:38–83  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

36// ValidateFileFlag checks mutual exclusion rules for the --file flag.
37// Returns nil if file is empty (flag not provided).
38func 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.

Callers 3

buildServiceRequestFunction · 0.92
buildAPIRequestFunction · 0.92
TestValidateFileFlagFunction · 0.85

Calls 5

NewValidationErrorFunction · 0.92
ParseFileFlagFunction · 0.85
WithParamMethod · 0.80
WithParamsMethod · 0.80
WithHintMethod · 0.45

Tested by 1

TestValidateFileFlagFunction · 0.68