import type { ShellValue, VarAttr } from '../../../../shell/variable.ts'; import type { Session } from '../../../session/session.ts'; import type { SessionView } from '../../../../ops/types.ts'; import type { Result } from '../types.ts'; export declare function premark(view: SessionView, name: string, shaping: ReadonlySet): Promise; /** * Store a declaration's array literals through the session door. * * The builtin owns the store so a refusal speaks in its own voice: * readonly is the shell's rule, checked per name before the door, and * the door's gate covers the policy half. Names are processed in * order, so an earlier operand stays stored when a later one refuses, * as bash does. Returns the refusal result, or null when every * literal stored. * * `mark` is the attribute the declaring keyword puts on each stored * name: Readonly for `readonly`, Export for `export`. An attribute * rather than a bool because both keywords stage array literals through * here and hardcoding one of them silently dropped the other: * `export ARR=(a b)` stored the array and never marked it, so GNU's * `declare -ax` came out `declare -a`. * * `stored` is filled with each name that actually stored, in order. A * declaration keeps its valid operands when a sibling refuses, so the * caller cannot read "what was written" off the aggregate exit status. * * `on` is the direction of that mark. `export -n ARR=(b)` stores the * array and takes the attribute *off*, and the store keeps whatever the * name already carried, so leaving the mark unapplied left an exported * array exported. * * A readonly refusal of an array literal is a variable-assignment error * in GNU, not a builtin failure: for `export`/`readonly` (and `declare` * at top level) `fatal` abandons the rest of the line, while `local` * and a function-scoped `declare` refuse in the builtin's voice and the * body keeps running (pinned on bash 5.2, debian:stable-slim). * * `assoc` means the declaration carried `-A`, so every literal builds * an associative map; without it a name that already holds one still * builds a map, since a plain `m+=([k]=v)` keeps the variable's own * kind. `errors` is filled with bash-voiced refusal lines for the * plain words a keyed associative literal cannot take; the caller * folds them into its exit status, because GNU stores the valid * elements and still fails the builtin. */ export declare function storeStagedArrays(cmd: string, session: Session, view: SessionView, arrays: { name: string; append: boolean; items: string[]; }[], mark?: VarAttr | null, on?: boolean, fatal?: boolean, stored?: string[] | null, assoc?: boolean, errors?: string[] | null, shaping?: ReadonlySet, globalScope?: boolean): Promise; /** * Quote a value the way bash `declare -p` / `export -p` does. * * A value holding any control character takes the `$'...'` form, with the * named escapes bash uses (`\a \b \t \n \v \f \r`, and `\E` for escape) and * three-digit octal for the rest; `"`, `$` and backtick need no escaping * there because `$'...'` does not expand. Everything else is double-quoted * with escapes for `\`, `"`, `$` and backtick. Non-ASCII printable text * stays literal, which is what bash emits in a UTF-8 locale. */ export declare function bashDeclareQuote(value: string): string; export declare function splitDeclFlags(args: string[], allowed: Set): { flags: Set; names: string[]; bad: string | null; }; /** * The `=(...)` tail of an associative `declare` line. * * Sorted keys (mirage's pinned order, where GNU prints hash order) and * GNU's trailing space before the closing paren, which an empty map * does not carry: `m=([a]="1" )` but `m=()`. */ export declare function assocBody(amap: Readonly>): string; /** * Mark names for export, or print them (`export -p` / bare `export`). * * With no name operands, prints every entry in `session.env` as * `declare -x NAME="value"`. Invalid option characters fail with status 2. * Writes go through the session view, so readonly refusal and the * preSession policy gate fire here exactly as for any other writer. */ /** * GNU's `not a valid identifier` line for one declaration operand. * * A declaration builtin refuses a name it cannot declare rather than * storing it: `export 1BAD=x` used to land a variable that `$1BAD` can * never name back (bash reads that as `$1` then `BAD`) and then shipped * it to every child environment. * * Which text GNU quotes depends on why the word failed, and both * spellings are pinned. A word that is not a valid assignment at all is * echoed whole (``export: `1BAD=x'``); a word whose target parses but is * not a plain name -- an array element -- is echoed as just that target * (``export: `arr[0]'``), since the value it would have taken is not * what is wrong with it. */ export declare function identifierRefusal(cmd: string, word: string): string | null; /** * Render the refusals collected while declaring names. * * One line per bad operand, exit 1, and the good operands on the same * line are already stored: GNU reports each and keeps going, so * `export GOOD=1 1BAD=x GOOD2=2` exports both good names. */ export declare function identifierFailure(cmd: string, errors: string[]): Result; /** * The `declare -p` line for one name, or null when it has none. * * The attribute cluster is `attrLetters`, which is why this renders * `declare -rx` and `declare -ar` without a table of its own: the record * already knows its own letters and their print order. bash spells an * empty cluster `--`, and that spelling is the caller's because only a * `declare` line needs it. * * A hidden name answers null, the same way `isReadonly` answers false for * one: reporting it as declared would leak it. */ export declare function declareLine(session: Session, name: string): string | null; /** * Run `declare -p`: render declarations for names, or for all. * * With names, they print in the order given and a name that does not * exist is reported on stderr without stopping the rest, exiting 1 at the * end -- GNU prints the names it knows and refuses only the ones it does * not. Bare `declare -p` lists every visible name sorted. */ export declare function handleDeclarePrint(names: string[], session: Session): Result; /** The `unset` refusal for a function `readonly -f` froze. */ export declare function readonlyFunctionUnset(name: string): Result; /** * Run `readonly -f`: freeze the named functions, or list the frozen. * * A frozen function refuses redefinition and `unset -f` with its own * message, exit 1, and the old body stays. A name that is not a * function is `not a function`, exit 1, and the other operands still * freeze. With no names, lists the frozen functions as `declare -fr * NAME`; GNU prints each body first through its own pretty-printer, * which mirage does not carry, so the body line is the one deliberate * omission. */ export declare function readonlyFunctions(session: Session, names: readonly string[]): Result; /** * Run the function half of `declare`: `-f` / `-F` / `-rf`. * * `-F NAME` prints the name; `-f NAME` prints `declare -f NAME` where * GNU prints the reformatted body (mirage carries no pretty-printer, so * the name row is the deliberate stand-in, the same shape `-F` and * `readonly -f` list in). A missing name is exit 1 with no message. * With `-r` the named functions freeze, as `readonly -f` does. With no * names, `-F` lists every function and `-f` lists them the same way. */ export declare function handleDeclareFunctions(cmd: string, session: Session, flags: ReadonlySet, names: readonly string[]): Result; /** * Record the caller's array before a function shadows `name`. * * `local -a` / `declare -a` inside a function shadow the caller's array, * so the old value (or its absence) has to be remembered for the teardown * in `executeCommand`. Returns true when a function scope is active, so * the caller should shadow rather than reuse whatever is already there. */ export declare function noteLocalArray(session: Session, name: string): boolean; /** * Declare names in the running function's scope, or globally. * * `cmd` is the spelling that reached here: `declare` and `typeset` route * through this handler and must say their own name in a diagnostic, not * `local`. */ /** * The line `declare -n NAME=TARGET` earns when TARGET is unusable: bash * refuses a target that is not a variable name, a self reference, and * (mirage-only) a target spelled as an array element, since the resolver * maps names to names. */ export declare function namerefRefusal(cmd: string, name: string, target: string): string | null; /** * Store a `declare -g` value on the global record. Outside a function, * or for a name no frame on the call path shadows, an ordinary write; * otherwise the running locals live in `session.vars` and the global * record is what the outermost shadowing frame saved, so the write goes * through the door with the two swapped for its duration. */ export declare function writeGlobal(session: Session, view: SessionView, key: string, value: ShellValue): Promise; //# sourceMappingURL=declare.d.ts.map