MCPcopy Create free account
hub / github.com/Effect-TS/effect / wrapCommand

Function wrapCommand

packages/effect/src/unstable/cli/internal/wizard.ts:258–280  ·  view source on GitHub ↗
(commandLine: ReadonlyArray<string>)

Source from the content-addressed store, hash-verified

256}
257
258const 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
282const formatShellArg = (arg: string): string =>
283 /^[A-Za-z0-9_./:@%+=,-]+$/.test(arg) ? arg : `'${arg.replaceAll("'", `'"'"'`)}'`

Callers 1

renderCommandBlockFunction · 0.85

Calls 2

pushMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected