(command: string)
| 121 | } |
| 122 | |
| 123 | function trimAtPipe(command: string) { |
| 124 | if (!command) { |
| 125 | return ""; |
| 126 | } |
| 127 | let inSingle = false; |
| 128 | let inDouble = false; |
| 129 | for (let index = 0; index < command.length; index += 1) { |
| 130 | const char = command[index]; |
| 131 | if (char === "'" && !inDouble) { |
| 132 | inSingle = !inSingle; |
| 133 | continue; |
| 134 | } |
| 135 | if (char === '"' && !inSingle) { |
| 136 | inDouble = !inDouble; |
| 137 | continue; |
| 138 | } |
| 139 | if (char !== "|" || inSingle || inDouble) { |
| 140 | continue; |
| 141 | } |
| 142 | const prev = index > 0 ? command[index - 1] : ""; |
| 143 | const next = index + 1 < command.length ? command[index + 1] : ""; |
| 144 | const prevIsSpace = prev === "" || /\s/.test(prev); |
| 145 | const nextIsSpace = next === "" || /\s/.test(next); |
| 146 | if (!prevIsSpace || !nextIsSpace) { |
| 147 | continue; |
| 148 | } |
| 149 | return command.slice(0, index).trim(); |
| 150 | } |
| 151 | return command.trim(); |
| 152 | } |
| 153 | |
| 154 | function isOptionToken(token: string) { |
| 155 | return token.startsWith("-"); |
no outgoing calls
no test coverage detected