@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
70 lines • 4.32 kB
TypeScript
import type { LineFacts } from '../../types.ts';
import { type CommandSpec, type ParsedFlagValue, type ValueType, WordKind } from './types.ts';
import { type WordChoices } from './word_choice.ts';
export declare class ParsedArgs {
readonly flags: Record<string, ParsedFlagValue>;
readonly args: [string, ValueType][];
/** Selected PATH option values before cwd resolution, keyed like parseToKwargs. */
readonly rawPathFlags: Record<string, ParsedFlagValue>;
readonly pathFlagValues: string[];
readonly rawOperands: [string, ValueType][];
readonly textFlagValues: string[];
readonly warnings: string[];
readonly wordKinds: (ValueType | null)[];
readonly wordBases: (string | null)[];
readonly wordRoles: (WordKind | null)[];
readonly invalidOptions: string[];
readonly ambiguousOptions: [string, readonly string[]][];
readonly optionErrorKinds: string[];
readonly needsValueOptions: string[];
readonly invalidValueOptions: [string, string, WordChoices][];
readonly ambiguousValueOptions: [string, string, WordChoices][];
readonly invalidIntOptions: [string, string][];
readonly invalidFloatOptions: [string, string][];
readonly missingRequiredOptions: string[];
readonly missingRequiredOperands: string[];
readonly typedDests: string[];
readonly oldOptionNeedsValue: string | null;
readonly builtin: boolean;
readonly facts: Map<string, LineFacts>;
constructor(init: Pick<ParsedArgs, 'flags' | 'args'> & Partial<Pick<ParsedArgs, 'rawPathFlags' | 'pathFlagValues' | 'rawOperands' | 'textFlagValues' | 'warnings' | 'wordKinds' | 'wordBases' | 'wordRoles' | 'invalidOptions' | 'ambiguousOptions' | 'optionErrorKinds' | 'needsValueOptions' | 'invalidValueOptions' | 'ambiguousValueOptions' | 'invalidIntOptions' | 'invalidFloatOptions' | 'missingRequiredOptions' | 'missingRequiredOperands' | 'typedDests' | 'oldOptionNeedsValue' | 'builtin'>>);
paths(): string[];
texts(): string[];
}
/**
* Read one command line against a spec.
*
* `unknownIsOperand` says whether another parser reads this line after
* mirage. False is a GNU command, where mirage is the only parser the line
* will meet, so a dashed word the spec does not declare is `unrecognized
* option`. True is an installed CLI's node, where the spec is deliberately
* partial: mirage's `git log` declares the flags mirage enforces and git owns
* the rest, so an undeclared dashed word is handed back as an operand for git
* to refuse in git's own words and exit (`fatal: unrecognized argument: -p`).
* It comes last and defaults to the GNU answer, because it is a fact about
* the call rather than about the spec, and nothing on CommandSpec may say it:
* the shared grammar stays what POSIX and argparse can both express. It says
* nothing about `choices`, which compares the whole word for every spec
* unless the option declaring the set is one of the builtin word-choice
* declarations -- an identity the spec itself settles, so it is not a fact
* about the caller at all.
*
* `abbreviations` is the same kind of fact about the program reading the
* line: its own full table of long options (git's `--[no-]` notation), when it
* resolves an abbreviated long option against that table the way git's
* parse-options does. A partial spec cannot answer whether `--no-m` is
* ambiguous, since the option git would also match is one mirage never
* declared, so the program's table is what is asked; an empty table is a
* program that takes whole words only (git's revision walkers). Undefined
* leaves the getopt_long reading against the spec.
*
* The reading is kept per spec, keyed by everything it depends on (the
* environment only through the variables the spec declares), so every reader
* of one command shares one parse: read it, never change it. Words longer
* than PARSE_KEPT_CHARS in all are read afresh each time.
*
* `parse_command` in parser.py is the twin.
*/
export declare function parseCommand(spec: CommandSpec, argv: string[], cwd: string, cmdName?: string, env?: Readonly<Record<string, string>>, unknownIsOperand?: boolean, abbreviations?: readonly string[]): ParsedArgs;
export declare function parseToKwargs(parsed: ParsedArgs): Record<string, ParsedFlagValue>;
//# sourceMappingURL=parser.d.ts.map