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)
| 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. |
| 22 | func 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). |
no outgoing calls