MCPcopy Create free account
hub / github.com/EvoMap/evolver / splitCommandLine

Function splitCommandLine

src/ops/lifecycle.js:404–441  ·  view source on GitHub ↗
(cmd)

Source from the content-addressed store, hash-verified

402}
403
404function splitCommandLine(cmd) {
405 var tokens = [];
406 var current = '';
407 var quote = null;
408 var escaped = false;
409 var raw = String(cmd || '');
410 for (var i = 0; i < raw.length; i++) {
411 var ch = raw[i];
412 if (escaped) {
413 current += ch;
414 escaped = false;
415 continue;
416 }
417 if (ch === '\\') {
418 escaped = true;
419 continue;
420 }
421 if ((ch === '"' || ch === "'") && !quote) {
422 quote = ch;
423 continue;
424 }
425 if (ch === quote) {
426 quote = null;
427 continue;
428 }
429 if (/\s/.test(ch) && !quote) {
430 if (current) {
431 tokens.push(current);
432 current = '';
433 }
434 continue;
435 }
436 current += ch;
437 }
438 if (escaped) current += '\\';
439 if (current) tokens.push(current);
440 return tokens;
441}
442
443function looksLikeNodeToken(token) {
444 var base = path.basename(String(token || '').replace(/\\/g, '/')).toLowerCase();

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected