cli-kiss 0.2.6 → 0.2.8
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/README.md +62 -4
- package/dist/index.d.ts +135 -128
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/docs/.vitepress/config.mts +1 -1
- package/docs/.vitepress/theme/Layout.vue +16 -0
- package/docs/.vitepress/theme/index.ts +5 -1
- package/docs/.vitepress/theme/style.css +5 -1
- package/docs/guide/02_commands.md +1 -1
- package/docs/guide/03_options.md +11 -11
- package/docs/guide/05_input_types.md +9 -10
- package/docs/guide/06_run_as_cli.md +1 -1
- package/docs/index.md +2 -2
- package/docs/public/favicon.ico +0 -0
- package/docs/public/logo.png +0 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/lib/Command.ts +50 -30
- package/src/lib/Operation.ts +29 -21
- package/src/lib/Option.ts +198 -133
- package/src/lib/Positional.ts +46 -24
- package/src/lib/Reader.ts +194 -207
- package/src/lib/Run.ts +19 -8
- package/src/lib/Suggest.ts +78 -0
- package/src/lib/Type.ts +46 -48
- package/src/lib/Typo.ts +72 -47
- package/src/lib/Usage.ts +13 -13
- package/tests/unit.Reader.commons.ts +92 -116
- package/tests/unit.Reader.parsings.ts +14 -26
- package/tests/unit.Reader.shortBig.ts +81 -96
- package/tests/unit.command.aliases.ts +100 -0
- package/tests/unit.command.execute.ts +1 -1
- package/tests/unit.command.usage.ts +12 -6
- package/tests/unit.fuzzed.alternatives.ts +43 -0
- package/tests/unit.runner.colors.ts +11 -35
- package/tests/unit.runner.cycle.ts +181 -128
- package/tests/unit.runner.errors.ts +26 -19
- package/docs/public/hero.png +0 -0
- package/tests/unit.Reader.aliases.ts +0 -62
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { expect, it } from "@jest/globals";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ReaderArgs,
|
|
4
|
+
ReaderOptionNextGuard,
|
|
5
|
+
ReaderOptionRestGuard,
|
|
6
|
+
} from "../src";
|
|
3
7
|
|
|
4
8
|
it("run", async function () {
|
|
5
9
|
const stream = new ReaderArgs([
|
|
@@ -36,105 +40,97 @@ it("run", async function () {
|
|
|
36
40
|
|
|
37
41
|
expect(stream.consumePositional()).toStrictEqual("positional-0");
|
|
38
42
|
|
|
39
|
-
const kFlagUnset = stream.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
parsing: optionFlagParsing,
|
|
43
|
+
const kFlagUnset = stream.registerOptionLong({
|
|
44
|
+
key: "flag-unset",
|
|
45
|
+
nextGuard: optionFlagNextGuard,
|
|
43
46
|
});
|
|
44
|
-
const kFlagNo = stream.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
parsing: optionFlagParsing,
|
|
47
|
+
const kFlagNo = stream.registerOptionLong({
|
|
48
|
+
key: "no-flag-no",
|
|
49
|
+
nextGuard: optionFlagNextGuard,
|
|
48
50
|
});
|
|
49
|
-
const kFlagNormal = stream.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
parsing: optionFlagParsing,
|
|
51
|
+
const kFlagNormal = stream.registerOptionLong({
|
|
52
|
+
key: "flag-normal",
|
|
53
|
+
nextGuard: optionFlagNextGuard,
|
|
53
54
|
});
|
|
54
|
-
const kFlagPositive = stream.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
parsing: optionFlagParsing,
|
|
55
|
+
const kFlagPositive = stream.registerOptionLong({
|
|
56
|
+
key: "flag-positive",
|
|
57
|
+
nextGuard: optionFlagNextGuard,
|
|
58
58
|
});
|
|
59
|
-
const kFlagNegative = stream.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
parsing: optionFlagParsing,
|
|
59
|
+
const kFlagNegative = stream.registerOptionLong({
|
|
60
|
+
key: "flag-negative",
|
|
61
|
+
nextGuard: optionFlagNextGuard,
|
|
63
62
|
});
|
|
64
63
|
|
|
65
64
|
expect(stream.consumePositional()).toStrictEqual("positional-1");
|
|
66
65
|
|
|
67
|
-
const kOptionUnset = stream.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
parsing: optionValueFixedUniqueParsing,
|
|
66
|
+
const kOptionUnset = stream.registerOptionLong({
|
|
67
|
+
key: "option-unset",
|
|
68
|
+
nextGuard: optionValuedNextGuard,
|
|
71
69
|
});
|
|
72
|
-
const kOptionSplit = stream.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
parsing: optionValueFixedUniqueParsing,
|
|
70
|
+
const kOptionSplit = stream.registerOptionLong({
|
|
71
|
+
key: "option-split",
|
|
72
|
+
nextGuard: optionValuedNextGuard,
|
|
76
73
|
});
|
|
77
|
-
const kOptionJoin = stream.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
parsing: optionValueFixedUniqueParsing,
|
|
74
|
+
const kOptionJoin = stream.registerOptionLong({
|
|
75
|
+
key: "option-join",
|
|
76
|
+
nextGuard: optionValuedNextGuard,
|
|
81
77
|
});
|
|
82
78
|
|
|
83
|
-
const kA = stream.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
const kA = stream.registerOptionShort({
|
|
80
|
+
key: "a",
|
|
81
|
+
restGuard: optionFlagRestGuard,
|
|
82
|
+
nextGuard: optionFlagNextGuard,
|
|
87
83
|
});
|
|
88
|
-
const kB = stream.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
const kB = stream.registerOptionShort({
|
|
85
|
+
key: "b",
|
|
86
|
+
restGuard: optionValuedRestGuard,
|
|
87
|
+
nextGuard: optionValuedNextGuard,
|
|
92
88
|
});
|
|
93
89
|
|
|
94
|
-
const kC = stream.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
90
|
+
const kC = stream.registerOptionShort({
|
|
91
|
+
key: "c",
|
|
92
|
+
restGuard: optionFlagRestGuard,
|
|
93
|
+
nextGuard: optionFlagNextGuard,
|
|
98
94
|
});
|
|
99
|
-
const kD = stream.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
95
|
+
const kD = stream.registerOptionShort({
|
|
96
|
+
key: "d",
|
|
97
|
+
restGuard: optionValuedRestGuard,
|
|
98
|
+
nextGuard: optionValuedNextGuard,
|
|
103
99
|
});
|
|
104
100
|
|
|
105
|
-
const kE = stream.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
const kE = stream.registerOptionShort({
|
|
102
|
+
key: "e",
|
|
103
|
+
restGuard: optionFlagRestGuard,
|
|
104
|
+
nextGuard: optionFlagNextGuard,
|
|
109
105
|
});
|
|
110
|
-
const kF = stream.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
106
|
+
const kF = stream.registerOptionShort({
|
|
107
|
+
key: "f",
|
|
108
|
+
restGuard: optionValuedRestGuard,
|
|
109
|
+
nextGuard: optionValuedNextGuard,
|
|
114
110
|
});
|
|
115
111
|
|
|
116
112
|
expect(stream.consumePositional()).toStrictEqual("positional-2");
|
|
117
113
|
|
|
118
|
-
const kG = stream.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
114
|
+
const kG = stream.registerOptionShort({
|
|
115
|
+
key: "g",
|
|
116
|
+
restGuard: optionFlagRestGuard,
|
|
117
|
+
nextGuard: optionFlagNextGuard,
|
|
122
118
|
});
|
|
123
|
-
const kH = stream.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
const kH = stream.registerOptionShort({
|
|
120
|
+
key: "h",
|
|
121
|
+
restGuard: optionValuedRestGuard,
|
|
122
|
+
nextGuard: optionValuedNextGuard,
|
|
127
123
|
});
|
|
128
124
|
|
|
129
|
-
const kI = stream.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
125
|
+
const kI = stream.registerOptionShort({
|
|
126
|
+
key: "i",
|
|
127
|
+
restGuard: optionFlagRestGuard,
|
|
128
|
+
nextGuard: optionFlagNextGuard,
|
|
133
129
|
});
|
|
134
|
-
const kJ = stream.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
130
|
+
const kJ = stream.registerOptionShort({
|
|
131
|
+
key: "j",
|
|
132
|
+
restGuard: optionValuedRestGuard,
|
|
133
|
+
nextGuard: optionValuedNextGuard,
|
|
138
134
|
});
|
|
139
135
|
|
|
140
136
|
expect(stream.consumePositional()).toStrictEqual("positional-3");
|
|
@@ -145,76 +141,56 @@ it("run", async function () {
|
|
|
145
141
|
expect(stream.consumePositional()).toStrictEqual("positional-4");
|
|
146
142
|
expect(stream.consumePositional()).toStrictEqual(undefined);
|
|
147
143
|
|
|
148
|
-
expect(
|
|
149
|
-
expect(
|
|
144
|
+
expect(kFlagUnset().values).toStrictEqual([]);
|
|
145
|
+
expect(kFlagNo().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
146
|
+
expect(kFlagNormal().values).toStrictEqual([
|
|
150
147
|
{ inlined: null, separated: [] },
|
|
151
148
|
]);
|
|
152
|
-
expect(
|
|
153
|
-
{ inlined: null, separated: [] },
|
|
154
|
-
]);
|
|
155
|
-
expect(stream.getOptionValues(kFlagPositive)).toStrictEqual([
|
|
149
|
+
expect(kFlagPositive().values).toStrictEqual([
|
|
156
150
|
{ inlined: "true", separated: [] },
|
|
157
151
|
]);
|
|
158
|
-
expect(
|
|
152
|
+
expect(kFlagNegative().values).toStrictEqual([
|
|
159
153
|
{ inlined: "false", separated: [] },
|
|
160
154
|
]);
|
|
161
155
|
|
|
162
|
-
expect(
|
|
163
|
-
expect(
|
|
156
|
+
expect(kOptionUnset().values).toStrictEqual([]);
|
|
157
|
+
expect(kOptionSplit().values).toStrictEqual([
|
|
164
158
|
{ inlined: null, separated: ["1.1"] },
|
|
165
159
|
{ inlined: null, separated: ["1.2"] },
|
|
166
160
|
]);
|
|
167
|
-
expect(
|
|
161
|
+
expect(kOptionJoin().values).toStrictEqual([
|
|
168
162
|
{ inlined: "2.1", separated: [] },
|
|
169
163
|
{ inlined: "2.2", separated: [] },
|
|
170
164
|
]);
|
|
171
165
|
|
|
172
|
-
expect(
|
|
173
|
-
|
|
174
|
-
]);
|
|
175
|
-
expect(stream.getOptionValues(kB)).toStrictEqual([
|
|
166
|
+
expect(kA().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
167
|
+
expect(kB().values).toStrictEqual([
|
|
176
168
|
{ inlined: null, separated: ["3.1"] },
|
|
177
169
|
{ inlined: null, separated: ["3.2"] },
|
|
178
170
|
]);
|
|
179
171
|
|
|
180
|
-
expect(
|
|
181
|
-
|
|
182
|
-
]);
|
|
183
|
-
expect(stream.getOptionValues(kD)).toStrictEqual([
|
|
172
|
+
expect(kC().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
173
|
+
expect(kD().values).toStrictEqual([
|
|
184
174
|
{ inlined: "4.1", separated: [] },
|
|
185
175
|
{ inlined: "4.2", separated: [] },
|
|
186
176
|
]);
|
|
187
177
|
|
|
188
|
-
expect(
|
|
189
|
-
|
|
190
|
-
]);
|
|
191
|
-
expect(stream.getOptionValues(kF)).toStrictEqual([
|
|
178
|
+
expect(kE().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
179
|
+
expect(kF().values).toStrictEqual([
|
|
192
180
|
{ inlined: "5.1", separated: [] },
|
|
193
181
|
{ inlined: "5.2", separated: [] },
|
|
194
182
|
]);
|
|
195
183
|
|
|
196
|
-
expect(
|
|
197
|
-
|
|
198
|
-
]);
|
|
199
|
-
expect(stream.getOptionValues(kH)).toStrictEqual([
|
|
200
|
-
{ inlined: "FALSE", separated: [] },
|
|
201
|
-
]);
|
|
184
|
+
expect(kG().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
185
|
+
expect(kH().values).toStrictEqual([{ inlined: "FALSE", separated: [] }]);
|
|
202
186
|
|
|
203
|
-
expect(
|
|
204
|
-
|
|
205
|
-
]);
|
|
206
|
-
expect(stream.getOptionValues(kJ)).toStrictEqual([
|
|
207
|
-
{ inlined: "TRUE", separated: [] },
|
|
208
|
-
]);
|
|
187
|
+
expect(kI().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
188
|
+
expect(kJ().values).toStrictEqual([{ inlined: "TRUE", separated: [] }]);
|
|
209
189
|
});
|
|
210
190
|
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
consumeNextArg: () => false,
|
|
214
|
-
};
|
|
191
|
+
const optionFlagRestGuard: ReaderOptionRestGuard = () => false;
|
|
192
|
+
const optionFlagNextGuard: ReaderOptionNextGuard = () => false;
|
|
215
193
|
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
inlined === null && separated.length === 0,
|
|
220
|
-
};
|
|
194
|
+
const optionValuedRestGuard: ReaderOptionRestGuard = () => true;
|
|
195
|
+
const optionValuedNextGuard: ReaderOptionNextGuard = (value) =>
|
|
196
|
+
value.inlined === null && value.separated.length === 0;
|
|
@@ -3,47 +3,35 @@ import { ReaderArgs } from "../src";
|
|
|
3
3
|
|
|
4
4
|
it("run", async function () {
|
|
5
5
|
const readerArgs1 = new ReaderArgs(["--val=1", "A", "B", "STOP", "C"]);
|
|
6
|
-
const kOptionVariadicStop = readerArgs1.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
consumeNextArg: (_inlined, separated, nextArg) =>
|
|
12
|
-
nextArg !== undefined && separated[separated.length - 1] !== "STOP",
|
|
13
|
-
},
|
|
6
|
+
const kOptionVariadicStop = readerArgs1.registerOptionLong({
|
|
7
|
+
key: "val",
|
|
8
|
+
nextGuard: (value, nextArg) =>
|
|
9
|
+
nextArg !== undefined &&
|
|
10
|
+
value.separated[value.separated.length - 1] !== "STOP",
|
|
14
11
|
});
|
|
15
12
|
expect(readerArgs1.consumePositional()).toStrictEqual("C");
|
|
16
13
|
expect(readerArgs1.consumePositional()).toStrictEqual(undefined);
|
|
17
|
-
expect(
|
|
14
|
+
expect(kOptionVariadicStop().values).toStrictEqual([
|
|
18
15
|
{ inlined: "1", separated: ["A", "B", "STOP"] },
|
|
19
16
|
]);
|
|
20
17
|
|
|
21
18
|
const readerArgs2 = new ReaderArgs(["--val=1", "A", "B", "C"]);
|
|
22
|
-
const kOptionVariadicFull = readerArgs2.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
parsing: {
|
|
26
|
-
consumeShortGroup: true,
|
|
27
|
-
consumeNextArg: (_inlined, _separated, nextArg) => nextArg !== undefined,
|
|
28
|
-
},
|
|
19
|
+
const kOptionVariadicFull = readerArgs2.registerOptionLong({
|
|
20
|
+
key: "val",
|
|
21
|
+
nextGuard: (_value, nextArg) => nextArg !== undefined,
|
|
29
22
|
});
|
|
30
23
|
expect(readerArgs2.consumePositional()).toStrictEqual(undefined);
|
|
31
|
-
expect(
|
|
24
|
+
expect(kOptionVariadicFull().values).toStrictEqual([
|
|
32
25
|
{ inlined: "1", separated: ["A", "B", "C"] },
|
|
33
26
|
]);
|
|
34
27
|
|
|
35
28
|
const readerArgs3 = new ReaderArgs(["--val=2", "A", "B", "--val=1", "C"]);
|
|
36
|
-
const kOptionVariadicKeyed = readerArgs3.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
parsing: {
|
|
40
|
-
consumeShortGroup: true,
|
|
41
|
-
consumeNextArg: (inlined, separated) =>
|
|
42
|
-
separated.length < Number(inlined ?? "0"),
|
|
43
|
-
},
|
|
29
|
+
const kOptionVariadicKeyed = readerArgs3.registerOptionLong({
|
|
30
|
+
key: "val",
|
|
31
|
+
nextGuard: (value) => value.separated.length < Number(value.inlined ?? "0"),
|
|
44
32
|
});
|
|
45
33
|
expect(readerArgs3.consumePositional()).toStrictEqual(undefined);
|
|
46
|
-
expect(
|
|
34
|
+
expect(kOptionVariadicKeyed().values).toStrictEqual([
|
|
47
35
|
{ inlined: "2", separated: ["A", "B"] },
|
|
48
36
|
{ inlined: "1", separated: ["C"] },
|
|
49
37
|
]);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { expect, it } from "@jest/globals";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ReaderArgs,
|
|
4
|
+
ReaderOptionNextGuard,
|
|
5
|
+
ReaderOptionRestGuard,
|
|
6
|
+
} from "../src";
|
|
3
7
|
|
|
4
8
|
it("run", async function () {
|
|
5
9
|
const stream = new ReaderArgs([
|
|
@@ -19,136 +23,117 @@ it("run", async function () {
|
|
|
19
23
|
|
|
20
24
|
expect(stream.consumePositional()).toStrictEqual("positional-0");
|
|
21
25
|
|
|
22
|
-
const kSofUnset = stream.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
const kSofUnset = stream.registerOptionShort({
|
|
27
|
+
key: "sof-unset",
|
|
28
|
+
restGuard: optionFlagRestGuard,
|
|
29
|
+
nextGuard: optionFlagNextGuard,
|
|
26
30
|
});
|
|
27
|
-
const kSofNormal = stream.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
const kSofNormal = stream.registerOptionShort({
|
|
32
|
+
key: "sof-normal",
|
|
33
|
+
restGuard: optionFlagRestGuard,
|
|
34
|
+
nextGuard: optionFlagNextGuard,
|
|
31
35
|
});
|
|
32
|
-
const kSofPositive = stream.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
const kSofPositive = stream.registerOptionShort({
|
|
37
|
+
key: "sof-positive",
|
|
38
|
+
restGuard: optionFlagRestGuard,
|
|
39
|
+
nextGuard: optionFlagNextGuard,
|
|
36
40
|
});
|
|
37
|
-
const kSofNegative = stream.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
const kSofNegative = stream.registerOptionShort({
|
|
42
|
+
key: "sof-negative",
|
|
43
|
+
restGuard: optionFlagRestGuard,
|
|
44
|
+
nextGuard: optionFlagNextGuard,
|
|
41
45
|
});
|
|
42
46
|
|
|
43
|
-
const kAa = stream.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
const kAa = stream.registerOptionShort({
|
|
48
|
+
key: "aa",
|
|
49
|
+
restGuard: optionFlagRestGuard,
|
|
50
|
+
nextGuard: optionFlagNextGuard,
|
|
47
51
|
});
|
|
48
|
-
const kBb = stream.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
const kBb = stream.registerOptionShort({
|
|
53
|
+
key: "bb",
|
|
54
|
+
restGuard: optionFlagRestGuard,
|
|
55
|
+
nextGuard: optionFlagNextGuard,
|
|
52
56
|
});
|
|
53
|
-
const kCc = stream.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
const kCc = stream.registerOptionShort({
|
|
58
|
+
key: "cc",
|
|
59
|
+
restGuard: optionFlagRestGuard,
|
|
60
|
+
nextGuard: optionFlagNextGuard,
|
|
57
61
|
});
|
|
58
62
|
|
|
59
63
|
expect(stream.consumePositional()).toStrictEqual("positional-1");
|
|
60
64
|
|
|
61
|
-
const kSovSplit = stream.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
const kSovSplit = stream.registerOptionShort({
|
|
66
|
+
key: "sov-split",
|
|
67
|
+
restGuard: optionValuedRestGuard,
|
|
68
|
+
nextGuard: optionValuedNextGuard,
|
|
65
69
|
});
|
|
66
|
-
const kSovJoin = stream.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
const kSovJoin = stream.registerOptionShort({
|
|
71
|
+
key: "sov-join",
|
|
72
|
+
restGuard: optionValuedRestGuard,
|
|
73
|
+
nextGuard: optionValuedNextGuard,
|
|
70
74
|
});
|
|
71
|
-
const kSovUnset = stream.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
const kSovUnset = stream.registerOptionShort({
|
|
76
|
+
key: "sov-unset",
|
|
77
|
+
restGuard: optionValuedRestGuard,
|
|
78
|
+
nextGuard: optionValuedNextGuard,
|
|
75
79
|
});
|
|
76
80
|
|
|
77
|
-
const kDd = stream.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
const kDd = stream.registerOptionShort({
|
|
82
|
+
key: "dd",
|
|
83
|
+
restGuard: optionFlagRestGuard,
|
|
84
|
+
nextGuard: optionFlagNextGuard,
|
|
81
85
|
});
|
|
82
|
-
const kEe = stream.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
const kEe = stream.registerOptionShort({
|
|
87
|
+
key: "ee",
|
|
88
|
+
restGuard: optionFlagRestGuard,
|
|
89
|
+
nextGuard: optionFlagNextGuard,
|
|
86
90
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
|
|
92
|
+
const kFf = stream.registerOptionShort({
|
|
93
|
+
key: "ff",
|
|
94
|
+
restGuard: optionFlagRestGuard,
|
|
95
|
+
nextGuard: optionFlagNextGuard,
|
|
91
96
|
});
|
|
92
|
-
const kGg = stream.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
const kGg = stream.registerOptionShort({
|
|
98
|
+
key: "gg",
|
|
99
|
+
restGuard: optionFlagRestGuard,
|
|
100
|
+
nextGuard: optionFlagNextGuard,
|
|
96
101
|
});
|
|
97
102
|
|
|
98
103
|
expect(stream.consumePositional()).toStrictEqual("positional-2");
|
|
99
104
|
|
|
100
|
-
expect(
|
|
101
|
-
expect(
|
|
102
|
-
|
|
103
|
-
]);
|
|
104
|
-
expect(stream.getOptionValues(kSofPositive)).toStrictEqual([
|
|
105
|
+
expect(kSofUnset().values).toStrictEqual([]);
|
|
106
|
+
expect(kSofNormal().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
107
|
+
expect(kSofPositive().values).toStrictEqual([
|
|
105
108
|
{ inlined: "true", separated: [] },
|
|
106
109
|
]);
|
|
107
|
-
expect(
|
|
110
|
+
expect(kSofNegative().values).toStrictEqual([
|
|
108
111
|
{ inlined: "false", separated: [] },
|
|
109
112
|
]);
|
|
110
113
|
|
|
111
|
-
expect(
|
|
112
|
-
|
|
113
|
-
]);
|
|
114
|
-
expect(stream.getOptionValues(kBb)).toStrictEqual([
|
|
115
|
-
{ inlined: null, separated: [] },
|
|
116
|
-
]);
|
|
117
|
-
expect(stream.getOptionValues(kCc)).toStrictEqual([
|
|
118
|
-
{ inlined: null, separated: [] },
|
|
119
|
-
]);
|
|
114
|
+
expect(kAa().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
115
|
+
expect(kBb().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
116
|
+
expect(kCc().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
120
117
|
|
|
121
|
-
expect(
|
|
122
|
-
expect(
|
|
118
|
+
expect(kSovUnset().values).toStrictEqual([]);
|
|
119
|
+
expect(kSovSplit().values).toStrictEqual([
|
|
123
120
|
{ inlined: null, separated: ["1.1"] },
|
|
124
121
|
{ inlined: null, separated: ["1.2"] },
|
|
125
122
|
]);
|
|
126
|
-
expect(
|
|
123
|
+
expect(kSovJoin().values).toStrictEqual([
|
|
127
124
|
{ inlined: "2.1", separated: [] },
|
|
128
125
|
{ inlined: "2.2", separated: [] },
|
|
129
126
|
]);
|
|
130
127
|
|
|
131
|
-
expect(
|
|
132
|
-
|
|
133
|
-
]);
|
|
134
|
-
expect(
|
|
135
|
-
{ inlined: null, separated: [] },
|
|
136
|
-
]);
|
|
137
|
-
expect(stream.getOptionValues(kFf)).toStrictEqual([
|
|
138
|
-
{ inlined: null, separated: [] },
|
|
139
|
-
]);
|
|
140
|
-
expect(stream.getOptionValues(kGg)).toStrictEqual([
|
|
141
|
-
{ inlined: null, separated: [] },
|
|
142
|
-
]);
|
|
128
|
+
expect(kDd().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
129
|
+
expect(kEe().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
130
|
+
expect(kFf().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
131
|
+
expect(kGg().values).toStrictEqual([{ inlined: null, separated: [] }]);
|
|
143
132
|
});
|
|
144
133
|
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
consumeNextArg: () => false,
|
|
148
|
-
};
|
|
134
|
+
const optionFlagRestGuard: ReaderOptionRestGuard = () => false;
|
|
135
|
+
const optionFlagNextGuard: ReaderOptionNextGuard = () => false;
|
|
149
136
|
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
inlined === null && separated.length === 0,
|
|
154
|
-
};
|
|
137
|
+
const optionValuedRestGuard: ReaderOptionRestGuard = () => true;
|
|
138
|
+
const optionValuedNextGuard: ReaderOptionNextGuard = (value) =>
|
|
139
|
+
value.inlined === null && value.separated.length === 0;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { expect, it } from "@jest/globals";
|
|
2
|
+
import {
|
|
3
|
+
command,
|
|
4
|
+
operation,
|
|
5
|
+
optionFlag,
|
|
6
|
+
optionRepeatable,
|
|
7
|
+
optionSingleValue,
|
|
8
|
+
ReaderArgs,
|
|
9
|
+
type,
|
|
10
|
+
} from "../src";
|
|
11
|
+
|
|
12
|
+
it("run", async function () {
|
|
13
|
+
const cmd = command(
|
|
14
|
+
{ description: "Description" },
|
|
15
|
+
operation(
|
|
16
|
+
{
|
|
17
|
+
options: {
|
|
18
|
+
option: optionRepeatable({
|
|
19
|
+
long: "option",
|
|
20
|
+
type: type(),
|
|
21
|
+
aliases: {
|
|
22
|
+
longs: ["option-alias1", "option-alias2"],
|
|
23
|
+
shorts: ["pts", "o"],
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
flag1: optionFlag({
|
|
27
|
+
long: "flag1",
|
|
28
|
+
aliases: {
|
|
29
|
+
longs: ["flag1-alias"],
|
|
30
|
+
shorts: ["fa"],
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
flag2: optionFlag({
|
|
34
|
+
long: "flag2",
|
|
35
|
+
aliases: {
|
|
36
|
+
longs: ["flag2-alias"],
|
|
37
|
+
shorts: ["fb"],
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
weird: optionRepeatable({
|
|
41
|
+
long: "2",
|
|
42
|
+
aliases: {
|
|
43
|
+
shorts: ["2o"],
|
|
44
|
+
},
|
|
45
|
+
type: type(),
|
|
46
|
+
}),
|
|
47
|
+
v1: optionSingleValue({
|
|
48
|
+
long: "v1",
|
|
49
|
+
aliases: {
|
|
50
|
+
shorts: ["va"],
|
|
51
|
+
},
|
|
52
|
+
type: type(),
|
|
53
|
+
impliedValueIfNotInlined: () => "bypass",
|
|
54
|
+
fallbackValueIfAbsent: () => undefined,
|
|
55
|
+
}),
|
|
56
|
+
v2: optionSingleValue({
|
|
57
|
+
long: "v2",
|
|
58
|
+
aliases: {
|
|
59
|
+
shorts: ["vb"],
|
|
60
|
+
},
|
|
61
|
+
type: type(),
|
|
62
|
+
impliedValueIfNotInlined: () => "bypass",
|
|
63
|
+
fallbackValueIfAbsent: () => undefined,
|
|
64
|
+
}),
|
|
65
|
+
},
|
|
66
|
+
positionals: [],
|
|
67
|
+
},
|
|
68
|
+
async function (_context, inputs) {
|
|
69
|
+
return inputs;
|
|
70
|
+
},
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
const readerArgs = new ReaderArgs([
|
|
74
|
+
"--option=1.1",
|
|
75
|
+
"--option-alias1=1.2",
|
|
76
|
+
"--option-alias2",
|
|
77
|
+
"1.3",
|
|
78
|
+
"-pts=1.4",
|
|
79
|
+
"-vbva=42",
|
|
80
|
+
"-o",
|
|
81
|
+
"1.5",
|
|
82
|
+
"--flag1-alias",
|
|
83
|
+
"--2=woops",
|
|
84
|
+
"-fb2o=1.6",
|
|
85
|
+
]);
|
|
86
|
+
const decoder = cmd.consumeAndMakeDecoder(readerArgs);
|
|
87
|
+
const interpreter = decoder.decodeAndMakeInterpreter();
|
|
88
|
+
const output = await interpreter.executeWithContext({});
|
|
89
|
+
expect(output).toStrictEqual({
|
|
90
|
+
options: {
|
|
91
|
+
option: ["1.1", "1.2", "1.3", "1.4", "1.5"],
|
|
92
|
+
flag1: true,
|
|
93
|
+
flag2: true,
|
|
94
|
+
weird: ["woops", "1.6"],
|
|
95
|
+
v1: "42",
|
|
96
|
+
v2: "bypass",
|
|
97
|
+
},
|
|
98
|
+
positionals: [],
|
|
99
|
+
});
|
|
100
|
+
});
|