SplitFileArg splits an argument of the form # , the way --attach reads ' # '. An existing path wins over the delimiter, since `#` is legal in filenames. path is arg itself when there was no `#` to split at. gh issue artifact create uses it for # , so `#` mea
(arg string)
| 103 | // split at. gh issue artifact create uses it for <file>#<name>, so `#` means |
| 104 | // the same there as in --attach. |
| 105 | func SplitFileArg(arg string) (path, text string) { |
| 106 | if _, err := os.Stat(arg); err == nil { |
| 107 | return arg, "" |
| 108 | } |
| 109 | // Scan from the last hash to the first, so the longest path that exists |
| 110 | // wins. That continues the rule above, where the whole argument is the |
| 111 | // longest match of all, and it leaves a hash inside the text usable. |
| 112 | for i := strings.LastIndex(arg, "#"); i > 0; i = strings.LastIndex(arg[:i], "#") { |
| 113 | if _, err := os.Stat(arg[:i]); err == nil { |
| 114 | return arg[:i], arg[i+1:] |
| 115 | } |
| 116 | } |
| 117 | // No candidate exists, so the argument names a file that is not there. The |
| 118 | // last hash keeps the error naming the path a reader would expect. |
| 119 | if idx := strings.LastIndex(arg, "#"); idx > 0 { |
| 120 | return arg[:idx], arg[idx+1:] |
| 121 | } |
| 122 | return arg, "" |
| 123 | } |
no outgoing calls