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.
Files changed (39) hide show
  1. package/README.md +62 -4
  2. package/dist/index.d.ts +135 -128
  3. package/dist/index.js +2 -2
  4. package/dist/index.js.map +1 -1
  5. package/docs/.vitepress/config.mts +1 -1
  6. package/docs/.vitepress/theme/Layout.vue +16 -0
  7. package/docs/.vitepress/theme/index.ts +5 -1
  8. package/docs/.vitepress/theme/style.css +5 -1
  9. package/docs/guide/02_commands.md +1 -1
  10. package/docs/guide/03_options.md +11 -11
  11. package/docs/guide/05_input_types.md +9 -10
  12. package/docs/guide/06_run_as_cli.md +1 -1
  13. package/docs/index.md +2 -2
  14. package/docs/public/favicon.ico +0 -0
  15. package/docs/public/logo.png +0 -0
  16. package/package.json +1 -1
  17. package/src/index.ts +1 -0
  18. package/src/lib/Command.ts +50 -30
  19. package/src/lib/Operation.ts +29 -21
  20. package/src/lib/Option.ts +198 -133
  21. package/src/lib/Positional.ts +46 -24
  22. package/src/lib/Reader.ts +194 -207
  23. package/src/lib/Run.ts +19 -8
  24. package/src/lib/Suggest.ts +78 -0
  25. package/src/lib/Type.ts +46 -48
  26. package/src/lib/Typo.ts +72 -47
  27. package/src/lib/Usage.ts +13 -13
  28. package/tests/unit.Reader.commons.ts +92 -116
  29. package/tests/unit.Reader.parsings.ts +14 -26
  30. package/tests/unit.Reader.shortBig.ts +81 -96
  31. package/tests/unit.command.aliases.ts +100 -0
  32. package/tests/unit.command.execute.ts +1 -1
  33. package/tests/unit.command.usage.ts +12 -6
  34. package/tests/unit.fuzzed.alternatives.ts +43 -0
  35. package/tests/unit.runner.colors.ts +11 -35
  36. package/tests/unit.runner.cycle.ts +181 -128
  37. package/tests/unit.runner.errors.ts +26 -19
  38. package/docs/public/hero.png +0 -0
  39. package/tests/unit.Reader.aliases.ts +0 -62
@@ -1,5 +1,9 @@
1
1
  import { expect, it } from "@jest/globals";
2
- import { ReaderArgs, ReaderOptionParsing } from "../src";
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.registerOption({
40
- longs: ["flag-unset"],
41
- shorts: [],
42
- parsing: optionFlagParsing,
43
+ const kFlagUnset = stream.registerOptionLong({
44
+ key: "flag-unset",
45
+ nextGuard: optionFlagNextGuard,
43
46
  });
44
- const kFlagNo = stream.registerOption({
45
- longs: ["no-flag-no"],
46
- shorts: [],
47
- parsing: optionFlagParsing,
47
+ const kFlagNo = stream.registerOptionLong({
48
+ key: "no-flag-no",
49
+ nextGuard: optionFlagNextGuard,
48
50
  });
49
- const kFlagNormal = stream.registerOption({
50
- longs: ["flag-normal"],
51
- shorts: [],
52
- parsing: optionFlagParsing,
51
+ const kFlagNormal = stream.registerOptionLong({
52
+ key: "flag-normal",
53
+ nextGuard: optionFlagNextGuard,
53
54
  });
54
- const kFlagPositive = stream.registerOption({
55
- longs: ["flag-positive"],
56
- shorts: [],
57
- parsing: optionFlagParsing,
55
+ const kFlagPositive = stream.registerOptionLong({
56
+ key: "flag-positive",
57
+ nextGuard: optionFlagNextGuard,
58
58
  });
59
- const kFlagNegative = stream.registerOption({
60
- longs: ["flag-negative"],
61
- shorts: [],
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.registerOption({
68
- longs: ["option-unset"],
69
- shorts: [],
70
- parsing: optionValueFixedUniqueParsing,
66
+ const kOptionUnset = stream.registerOptionLong({
67
+ key: "option-unset",
68
+ nextGuard: optionValuedNextGuard,
71
69
  });
72
- const kOptionSplit = stream.registerOption({
73
- longs: ["option-split"],
74
- shorts: [],
75
- parsing: optionValueFixedUniqueParsing,
70
+ const kOptionSplit = stream.registerOptionLong({
71
+ key: "option-split",
72
+ nextGuard: optionValuedNextGuard,
76
73
  });
77
- const kOptionJoin = stream.registerOption({
78
- longs: ["option-join"],
79
- shorts: [],
80
- parsing: optionValueFixedUniqueParsing,
74
+ const kOptionJoin = stream.registerOptionLong({
75
+ key: "option-join",
76
+ nextGuard: optionValuedNextGuard,
81
77
  });
82
78
 
83
- const kA = stream.registerOption({
84
- longs: [],
85
- shorts: ["a"],
86
- parsing: optionFlagParsing,
79
+ const kA = stream.registerOptionShort({
80
+ key: "a",
81
+ restGuard: optionFlagRestGuard,
82
+ nextGuard: optionFlagNextGuard,
87
83
  });
88
- const kB = stream.registerOption({
89
- longs: [],
90
- shorts: ["b"],
91
- parsing: optionValueFixedUniqueParsing,
84
+ const kB = stream.registerOptionShort({
85
+ key: "b",
86
+ restGuard: optionValuedRestGuard,
87
+ nextGuard: optionValuedNextGuard,
92
88
  });
93
89
 
94
- const kC = stream.registerOption({
95
- longs: [],
96
- shorts: ["c"],
97
- parsing: optionFlagParsing,
90
+ const kC = stream.registerOptionShort({
91
+ key: "c",
92
+ restGuard: optionFlagRestGuard,
93
+ nextGuard: optionFlagNextGuard,
98
94
  });
99
- const kD = stream.registerOption({
100
- longs: [],
101
- shorts: ["d"],
102
- parsing: optionValueFixedUniqueParsing,
95
+ const kD = stream.registerOptionShort({
96
+ key: "d",
97
+ restGuard: optionValuedRestGuard,
98
+ nextGuard: optionValuedNextGuard,
103
99
  });
104
100
 
105
- const kE = stream.registerOption({
106
- longs: [],
107
- shorts: ["e"],
108
- parsing: optionFlagParsing,
101
+ const kE = stream.registerOptionShort({
102
+ key: "e",
103
+ restGuard: optionFlagRestGuard,
104
+ nextGuard: optionFlagNextGuard,
109
105
  });
110
- const kF = stream.registerOption({
111
- longs: [],
112
- shorts: ["f"],
113
- parsing: optionValueFixedUniqueParsing,
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.registerOption({
119
- longs: [],
120
- shorts: ["g"],
121
- parsing: optionFlagParsing,
114
+ const kG = stream.registerOptionShort({
115
+ key: "g",
116
+ restGuard: optionFlagRestGuard,
117
+ nextGuard: optionFlagNextGuard,
122
118
  });
123
- const kH = stream.registerOption({
124
- longs: [],
125
- shorts: ["h"],
126
- parsing: optionFlagParsing,
119
+ const kH = stream.registerOptionShort({
120
+ key: "h",
121
+ restGuard: optionValuedRestGuard,
122
+ nextGuard: optionValuedNextGuard,
127
123
  });
128
124
 
129
- const kI = stream.registerOption({
130
- longs: [],
131
- shorts: ["i"],
132
- parsing: optionFlagParsing,
125
+ const kI = stream.registerOptionShort({
126
+ key: "i",
127
+ restGuard: optionFlagRestGuard,
128
+ nextGuard: optionFlagNextGuard,
133
129
  });
134
- const kJ = stream.registerOption({
135
- longs: [],
136
- shorts: ["j"],
137
- parsing: optionFlagParsing,
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(stream.getOptionValues(kFlagUnset)).toStrictEqual([]);
149
- expect(stream.getOptionValues(kFlagNo)).toStrictEqual([
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(stream.getOptionValues(kFlagNormal)).toStrictEqual([
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(stream.getOptionValues(kFlagNegative)).toStrictEqual([
152
+ expect(kFlagNegative().values).toStrictEqual([
159
153
  { inlined: "false", separated: [] },
160
154
  ]);
161
155
 
162
- expect(stream.getOptionValues(kOptionUnset)).toStrictEqual([]);
163
- expect(stream.getOptionValues(kOptionSplit)).toStrictEqual([
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(stream.getOptionValues(kOptionJoin)).toStrictEqual([
161
+ expect(kOptionJoin().values).toStrictEqual([
168
162
  { inlined: "2.1", separated: [] },
169
163
  { inlined: "2.2", separated: [] },
170
164
  ]);
171
165
 
172
- expect(stream.getOptionValues(kA)).toStrictEqual([
173
- { inlined: null, separated: [] },
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(stream.getOptionValues(kC)).toStrictEqual([
181
- { inlined: null, separated: [] },
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(stream.getOptionValues(kE)).toStrictEqual([
189
- { inlined: null, separated: [] },
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(stream.getOptionValues(kG)).toStrictEqual([
197
- { inlined: null, separated: [] },
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(stream.getOptionValues(kI)).toStrictEqual([
204
- { inlined: null, separated: [] },
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 optionFlagParsing: ReaderOptionParsing = {
212
- consumeShortGroup: false,
213
- consumeNextArg: () => false,
214
- };
191
+ const optionFlagRestGuard: ReaderOptionRestGuard = () => false;
192
+ const optionFlagNextGuard: ReaderOptionNextGuard = () => false;
215
193
 
216
- const optionValueFixedUniqueParsing: ReaderOptionParsing = {
217
- consumeShortGroup: true,
218
- consumeNextArg: (inlined, separated) =>
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.registerOption({
7
- longs: ["val"],
8
- shorts: [],
9
- parsing: {
10
- consumeShortGroup: true,
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(readerArgs1.getOptionValues(kOptionVariadicStop)).toStrictEqual([
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.registerOption({
23
- longs: ["val"],
24
- shorts: [],
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(readerArgs2.getOptionValues(kOptionVariadicFull)).toStrictEqual([
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.registerOption({
37
- longs: ["val"],
38
- shorts: [],
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(readerArgs3.getOptionValues(kOptionVariadicKeyed)).toStrictEqual([
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 { ReaderArgs, ReaderOptionParsing } from "../src";
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.registerOption({
23
- longs: [],
24
- shorts: ["sof-unset"],
25
- parsing: optionFlagParsing,
26
+ const kSofUnset = stream.registerOptionShort({
27
+ key: "sof-unset",
28
+ restGuard: optionFlagRestGuard,
29
+ nextGuard: optionFlagNextGuard,
26
30
  });
27
- const kSofNormal = stream.registerOption({
28
- shorts: ["sof-normal"],
29
- longs: [],
30
- parsing: optionFlagParsing,
31
+ const kSofNormal = stream.registerOptionShort({
32
+ key: "sof-normal",
33
+ restGuard: optionFlagRestGuard,
34
+ nextGuard: optionFlagNextGuard,
31
35
  });
32
- const kSofPositive = stream.registerOption({
33
- longs: [],
34
- shorts: ["sof-positive"],
35
- parsing: optionFlagParsing,
36
+ const kSofPositive = stream.registerOptionShort({
37
+ key: "sof-positive",
38
+ restGuard: optionFlagRestGuard,
39
+ nextGuard: optionFlagNextGuard,
36
40
  });
37
- const kSofNegative = stream.registerOption({
38
- longs: [],
39
- shorts: ["sof-negative"],
40
- parsing: optionFlagParsing,
41
+ const kSofNegative = stream.registerOptionShort({
42
+ key: "sof-negative",
43
+ restGuard: optionFlagRestGuard,
44
+ nextGuard: optionFlagNextGuard,
41
45
  });
42
46
 
43
- const kAa = stream.registerOption({
44
- longs: [],
45
- shorts: ["aa"],
46
- parsing: optionFlagParsing,
47
+ const kAa = stream.registerOptionShort({
48
+ key: "aa",
49
+ restGuard: optionFlagRestGuard,
50
+ nextGuard: optionFlagNextGuard,
47
51
  });
48
- const kBb = stream.registerOption({
49
- longs: [],
50
- shorts: ["bb"],
51
- parsing: optionFlagParsing,
52
+ const kBb = stream.registerOptionShort({
53
+ key: "bb",
54
+ restGuard: optionFlagRestGuard,
55
+ nextGuard: optionFlagNextGuard,
52
56
  });
53
- const kCc = stream.registerOption({
54
- longs: [],
55
- shorts: ["cc"],
56
- parsing: optionFlagParsing,
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.registerOption({
62
- longs: [],
63
- shorts: ["sov-split"],
64
- parsing: optionValueFixedUniqueParsing,
65
+ const kSovSplit = stream.registerOptionShort({
66
+ key: "sov-split",
67
+ restGuard: optionValuedRestGuard,
68
+ nextGuard: optionValuedNextGuard,
65
69
  });
66
- const kSovJoin = stream.registerOption({
67
- longs: [],
68
- shorts: ["sov-join"],
69
- parsing: optionValueFixedUniqueParsing,
70
+ const kSovJoin = stream.registerOptionShort({
71
+ key: "sov-join",
72
+ restGuard: optionValuedRestGuard,
73
+ nextGuard: optionValuedNextGuard,
70
74
  });
71
- const kSovUnset = stream.registerOption({
72
- longs: [],
73
- shorts: ["sov-unset"],
74
- parsing: optionValueFixedUniqueParsing,
75
+ const kSovUnset = stream.registerOptionShort({
76
+ key: "sov-unset",
77
+ restGuard: optionValuedRestGuard,
78
+ nextGuard: optionValuedNextGuard,
75
79
  });
76
80
 
77
- const kDd = stream.registerOption({
78
- longs: [],
79
- shorts: ["dd"],
80
- parsing: optionFlagParsing,
81
+ const kDd = stream.registerOptionShort({
82
+ key: "dd",
83
+ restGuard: optionFlagRestGuard,
84
+ nextGuard: optionFlagNextGuard,
81
85
  });
82
- const kEe = stream.registerOption({
83
- longs: [],
84
- shorts: ["ee"],
85
- parsing: optionFlagParsing,
86
+ const kEe = stream.registerOptionShort({
87
+ key: "ee",
88
+ restGuard: optionFlagRestGuard,
89
+ nextGuard: optionFlagNextGuard,
86
90
  });
87
- const kFf = stream.registerOption({
88
- longs: [],
89
- shorts: ["ff"],
90
- parsing: optionFlagParsing,
91
+
92
+ const kFf = stream.registerOptionShort({
93
+ key: "ff",
94
+ restGuard: optionFlagRestGuard,
95
+ nextGuard: optionFlagNextGuard,
91
96
  });
92
- const kGg = stream.registerOption({
93
- longs: [],
94
- shorts: ["gg"],
95
- parsing: optionFlagParsing,
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(stream.getOptionValues(kSofUnset)).toStrictEqual([]);
101
- expect(stream.getOptionValues(kSofNormal)).toStrictEqual([
102
- { inlined: null, separated: [] },
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(stream.getOptionValues(kSofNegative)).toStrictEqual([
110
+ expect(kSofNegative().values).toStrictEqual([
108
111
  { inlined: "false", separated: [] },
109
112
  ]);
110
113
 
111
- expect(stream.getOptionValues(kAa)).toStrictEqual([
112
- { inlined: null, separated: [] },
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(stream.getOptionValues(kSovUnset)).toStrictEqual([]);
122
- expect(stream.getOptionValues(kSovSplit)).toStrictEqual([
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(stream.getOptionValues(kSovJoin)).toStrictEqual([
123
+ expect(kSovJoin().values).toStrictEqual([
127
124
  { inlined: "2.1", separated: [] },
128
125
  { inlined: "2.2", separated: [] },
129
126
  ]);
130
127
 
131
- expect(stream.getOptionValues(kDd)).toStrictEqual([
132
- { inlined: null, separated: [] },
133
- ]);
134
- expect(stream.getOptionValues(kEe)).toStrictEqual([
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 optionFlagParsing: ReaderOptionParsing = {
146
- consumeShortGroup: false,
147
- consumeNextArg: () => false,
148
- };
134
+ const optionFlagRestGuard: ReaderOptionRestGuard = () => false;
135
+ const optionFlagNextGuard: ReaderOptionNextGuard = () => false;
149
136
 
150
- const optionValueFixedUniqueParsing: ReaderOptionParsing = {
151
- consumeShortGroup: true,
152
- consumeNextArg: (inlined, separated) =>
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
+ });