(commandLine: ReadonlyArray<string>)
| 256 | } |
| 257 | |
| 258 | const wrapCommand = (commandLine: ReadonlyArray<string>): Array<string> => { |
| 259 | const width = 88 |
| 260 | const firstIndent = " $ " |
| 261 | const continuationIndent = " " |
| 262 | const args = commandLine.map(formatShellArg) |
| 263 | const lines: Array<string> = [] |
| 264 | let current = firstIndent |
| 265 | |
| 266 | for (const arg of args) { |
| 267 | const separator = current === firstIndent || current === continuationIndent ? "" : " " |
| 268 | if (current.length + separator.length + arg.length > width && current !== firstIndent) { |
| 269 | lines.push(`${current} \\`) |
| 270 | current = `${continuationIndent}${arg}` |
| 271 | } else { |
| 272 | current += `${separator}${arg}` |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | if (current !== firstIndent) { |
| 277 | lines.push(current) |
| 278 | } |
| 279 | return lines |
| 280 | } |
| 281 | |
| 282 | const formatShellArg = (arg: string): string => |
| 283 | /^[A-Za-z0-9_./:@%+=,-]+$/.test(arg) ? arg : `'${arg.replaceAll("'", `'"'"'`)}'` |
no test coverage detected