Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/dxx/src/lib/xArgs.ts>argsItSync

🚀 (Deno) enhanced executor
Latest
function argsItSync
import { argsItSync } from "https://deno.land/x/dxx@rf/src/lib/xArgs.ts";

Incrementally parse and 'shell'-expand argument text; returning a lazy iterator of ArgIncrementSync's.

  • Performs bash-like expansion (compatible with the Bash v4.3 specification).
  • Quotes (single or double) are used to protect braces, tildes, and globs from expansion; unbalanced quotes are allowed (and parsed as if completed by the end of the string). Otherwise, no character escape sequences are recognized.
  • Brace expansion is fully implemented (including nested braces and "brace bomb" protections).
  • Glob expansion supports globstar and full extended glob syntax.

Uses the braces* and picomatch JS modules.

Examples

Example 1

// eg, for `deno`, `dxr`, `env`, `xargs`, ...
const argsText = '--processOptions ... targetExecutable {.,}"text*string" ./src/file_{1..10..2}_*.ts';
const argIt = argsItSync(argsText);
const processArgs = [];
let targetArgsText = '';
let options = null;
for (const [arg, restOfArgsText] of argIt) {
	processArgs.push(arg);
	options = getOptions(processArgs);
	if (options.targetExecutable) {
		targetArgsText = restOfArgsText;
		break;
	}
}
if (options.targetExecutable) {
	// run `targetExecutable` with `targetArgsText` (un-processed argument text)
}

Parameters

argsText: string
optional
options: ArgsOptions = [UNSUPPORTED]

Returns

IterableIterator<ArgIncrementSync>

Async iterator of expansions with corresponding remaining argument string (ie, [arg, restOfArgS])