@loomcli/core 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/application.d.ts +11 -6
- package/dist/application.js +11 -5
- package/dist/chain.d.ts +28 -17
- package/dist/chain.js +11 -10
- package/dist/command-rules.d.ts +1 -1
- package/dist/command-rules.js +2 -2
- package/dist/command.d.ts +31 -47
- package/dist/command.js +136 -170
- package/dist/errors.d.ts +22 -21
- package/dist/errors.js +38 -18
- package/dist/globals.d.ts +48 -22
- package/dist/globals.js +63 -22
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/input-rules.d.ts +16 -2
- package/dist/input-rules.js +40 -5
- package/dist/inspect.d.ts +35 -11
- package/dist/inspect.js +69 -66
- package/dist/locate.js +52 -60
- package/dist/options.d.ts +94 -83
- package/dist/options.js +298 -260
- package/dist/parse.d.ts +162 -0
- package/dist/parse.js +601 -0
- package/dist/plugin-rules.d.ts +2 -4
- package/dist/plugin-rules.js +3 -8
- package/dist/plugin.d.ts +26 -21
- package/dist/plugin.js +10 -45
- package/dist/sources.d.ts +18 -9
- package/dist/sources.js +46 -16
- package/dist/types.d.ts +68 -28
- package/dist/validation.d.ts +84 -31
- package/dist/validation.js +222 -110
- package/package.json +1 -1
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { ArgumentSlot, BuiltCommand, BuiltGraph } from './command.js';
|
|
2
|
+
import type { LoomError } from './errors.js';
|
|
3
|
+
import type { OptionValues, SpellingTable, TableSpelling } from './options.js';
|
|
4
|
+
/**
|
|
5
|
+
* Whether a word is an option word: `--` and at least one more character, or `-` and an ASCII
|
|
6
|
+
* letter. Every other word is a plain word, so `-`, `-5`, and `-.5` are values or arguments. The
|
|
7
|
+
* parser and `locate` read each word through this rule.
|
|
8
|
+
*/
|
|
9
|
+
declare function isOptionWord(word: string): boolean;
|
|
10
|
+
/** A word the grammar never consumes as a separate value: an option word or the bare `--`. */
|
|
11
|
+
declare function refusesValue(word: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* One occurrence an option word holds, read against one table before it touches a value. `lead`
|
|
14
|
+
* marks a value the word itself carries, after `=` or a short value letter, and holds the part of
|
|
15
|
+
* the word before it.
|
|
16
|
+
*/
|
|
17
|
+
type Occurrence = {
|
|
18
|
+
kind: 'value';
|
|
19
|
+
option: TableSpelling;
|
|
20
|
+
spelling: string;
|
|
21
|
+
/** A string, a Boolean's own value, or the `1` one occurrence of a counted option adds. */
|
|
22
|
+
value: string | boolean | number;
|
|
23
|
+
lead?: string;
|
|
24
|
+
/** A bare spelling of a string option with an implied value, which supplied that value. */
|
|
25
|
+
implied?: true;
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'unknown';
|
|
28
|
+
spelling: string;
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'misplaced';
|
|
31
|
+
spelling: string;
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'unexpected';
|
|
34
|
+
option: ValuelessSpelling;
|
|
35
|
+
spelling: string;
|
|
36
|
+
value: string;
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'repeated';
|
|
39
|
+
option: TableSpelling;
|
|
40
|
+
spelling: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'missing';
|
|
43
|
+
option: TableSpelling;
|
|
44
|
+
spelling: string;
|
|
45
|
+
} | {
|
|
46
|
+
kind: 'awaiting';
|
|
47
|
+
option: TableSpelling;
|
|
48
|
+
spelling: string;
|
|
49
|
+
};
|
|
50
|
+
/** A spelling of an option that takes no value: a Boolean option or a counted option. */
|
|
51
|
+
type ValuelessSpelling = TableSpelling & {
|
|
52
|
+
type: 'boolean' | 'count';
|
|
53
|
+
};
|
|
54
|
+
/** What one option word holds, in order, and whether its last occurrence took the next word. */
|
|
55
|
+
interface WordReading {
|
|
56
|
+
occurrences: readonly Occurrence[];
|
|
57
|
+
takesNext: boolean;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* What one option word is read against: a table, and the values earlier words supplied, so an
|
|
61
|
+
* option that does not collect and was supplied already is a repeat that ends the walk.
|
|
62
|
+
*/
|
|
63
|
+
interface WordContext {
|
|
64
|
+
table: SpellingTable;
|
|
65
|
+
values: {
|
|
66
|
+
globals: OptionValues;
|
|
67
|
+
locals: OptionValues;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** One option word read against one table, with the word after it as its possible value. */
|
|
71
|
+
declare function readOptionWord(context: WordContext, word: string, next: string | undefined): WordReading;
|
|
72
|
+
/**
|
|
73
|
+
* The first structural fault in word order: a failure, or the position of the first positional no
|
|
74
|
+
* slot accepts, which becomes a failure once every later positional is known. `at` is the order in
|
|
75
|
+
* which the faulted occurrence was read, so a fault found later than it was read still ranks by it.
|
|
76
|
+
*/
|
|
77
|
+
type HeldFault = ({
|
|
78
|
+
error: LoomError;
|
|
79
|
+
} | {
|
|
80
|
+
extra: number;
|
|
81
|
+
}) & {
|
|
82
|
+
at: number;
|
|
83
|
+
};
|
|
84
|
+
/** A string option the last word left waiting for its value. */
|
|
85
|
+
interface AwaitingValue {
|
|
86
|
+
global: boolean;
|
|
87
|
+
name: string;
|
|
88
|
+
spelling: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The names a routing failure offers: the canonical names of the visible, current children, in
|
|
92
|
+
* authoring order. A candidate list is a listing, so a hidden or a deprecated child is absent from
|
|
93
|
+
* it, as completion leaves them out, and a parent whose children are all hidden or deprecated
|
|
94
|
+
* offers none. A deprecated child typed in full still routes.
|
|
95
|
+
*/
|
|
96
|
+
declare function candidatesOf(command: BuiltCommand): string[];
|
|
97
|
+
/**
|
|
98
|
+
* The slot the positional at one index fills: the slot at that index, else a variadic last slot,
|
|
99
|
+
* which accepts every later positional, else none. Binding and `locate` read positions through it.
|
|
100
|
+
*/
|
|
101
|
+
declare function argumentSlot(slots: readonly ArgumentSlot[], position: number): ArgumentSlot | undefined;
|
|
102
|
+
/** Every word the reading of one word list found, which may stop short of a complete invocation. */
|
|
103
|
+
interface WordsRead {
|
|
104
|
+
awaiting: AwaitingValue | undefined;
|
|
105
|
+
command: BuiltCommand;
|
|
106
|
+
/** Whether the routed Command read a word, so no later plain word names a child. */
|
|
107
|
+
committed: boolean;
|
|
108
|
+
delimited: boolean;
|
|
109
|
+
fault: HeldFault | undefined;
|
|
110
|
+
globalFault: boolean;
|
|
111
|
+
passthrough: string[];
|
|
112
|
+
path: string[];
|
|
113
|
+
positionals: string[];
|
|
114
|
+
/** How many occurrences and positionals were read, the order a fault at the end ranks by. */
|
|
115
|
+
read: number;
|
|
116
|
+
supplied: readonly string[];
|
|
117
|
+
values: {
|
|
118
|
+
globals: OptionValues;
|
|
119
|
+
locals: OptionValues;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* How one word list is read: who hears each routed name, and whether the list is the earlier words
|
|
124
|
+
* of an unfinished invocation, as `locate` reads them. A word after such a list may continue
|
|
125
|
+
* routing, so routing has not ended where the list runs out at a Command with children, and a
|
|
126
|
+
* parent's own option stays unbound.
|
|
127
|
+
*/
|
|
128
|
+
interface ReadOptions {
|
|
129
|
+
partial?: boolean;
|
|
130
|
+
walked?: (path: readonly string[]) => void;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Reads a word list through routing, against the global options and the own options of each
|
|
134
|
+
* Command with an action and children it passes through, binds those own options to the Command
|
|
135
|
+
* routing reached once routing has ended, and then reads that Command's own words, up to the first
|
|
136
|
+
* bare `--`, against the one table it holds.
|
|
137
|
+
* Parsing continues past a fault, so every global option is found wherever it sits, and only the
|
|
138
|
+
* first fault in word order is held. Only an unknown Command throws.
|
|
139
|
+
*/
|
|
140
|
+
declare function readWords(graph: BuiltGraph, words: readonly string[], options?: ReadOptions): WordsRead;
|
|
141
|
+
/** One complete invocation, read through routing and the routed Command's table. */
|
|
142
|
+
interface ParsedInvocation {
|
|
143
|
+
command: BuiltCommand;
|
|
144
|
+
/** The first structural fault in word order, which core holds to the dispatch boundary. */
|
|
145
|
+
fault: LoomError | undefined;
|
|
146
|
+
/** Whether a global option faulted, which leaves every middleware's `options` `null`. */
|
|
147
|
+
globalFault: boolean;
|
|
148
|
+
passthrough: string[];
|
|
149
|
+
path: readonly string[];
|
|
150
|
+
positionals: string[];
|
|
151
|
+
values: {
|
|
152
|
+
globals: OptionValues;
|
|
153
|
+
locals: OptionValues;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Parses a complete invocation, where a string option still waiting for its value at the end of
|
|
158
|
+
* the words is a missing value.
|
|
159
|
+
*/
|
|
160
|
+
declare function parseInvocation(graph: BuiltGraph, argv: readonly string[], walked: (path: readonly string[]) => void): ParsedInvocation;
|
|
161
|
+
export type { AwaitingValue, ParsedInvocation, WordsRead };
|
|
162
|
+
export { argumentSlot, candidatesOf, isOptionWord, parseInvocation, readOptionWord, readWords, refusesValue, };
|