MCPcopy Index your code
hub / github.com/larksuite/cli / ParseFileFlag

Function ParseFileFlag

internal/cmdutil/fileupload.go:22–34  ·  view source on GitHub ↗

ParseFileFlag parses a --file flag value into its components. The format is either "path" or "field=path". When no explicit "field=" prefix is present, defaultField is used as the field name. A path of "-" indicates stdin; in that case filePath is empty and isStdin is true.

(raw, defaultField string)

Source from the content-addressed store, hash-verified

20// prefix is present, defaultField is used as the field name.
21// A path of "-" indicates stdin; in that case filePath is empty and isStdin is true.
22func ParseFileFlag(raw, defaultField string) (fieldName, filePath string, isStdin bool) {
23 if idx := strings.IndexByte(raw, '='); idx > 0 {
24 fieldName = raw[:idx]
25 filePath = raw[idx+1:]
26 } else {
27 fieldName = defaultField
28 filePath = raw
29 }
30 if filePath == "-" {
31 return fieldName, "", true
32 }
33 return fieldName, filePath, false
34}
35
36// ValidateFileFlag checks mutual exclusion rules for the --file flag.
37// Returns nil if file is empty (flag not provided).

Callers 4

buildServiceRequestFunction · 0.92
buildAPIRequestFunction · 0.92
ValidateFileFlagFunction · 0.85
TestParseFileFlagFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseFileFlagFunction · 0.68