import { argsItAsync } 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.
Examples
Example 1
Example 1
// eg, for `deno`, `dxr`, `env`, `xargs`, ...
const argsText = '--processOptions ... targetExecutable {.,}"text*string" ./src/file_{1..10..2}_*.ts';
const argIt = argsItAsync(argsText);
const processArgs = [];
let targetArgsText = '';
let options = null;
for await (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
optional
options: ArgsOptions = [UNSUPPORTED]Returns
AsyncIterableIterator<ArgIncrementAsync>
Async iterator of expansions with corresponding remaining argument string (ie, [arg, restOfArgS]
)