@optique/core 0.4.0-dev.51 → 0.4.0-dev.53
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 +2 -3
- package/dist/facade.cjs +16 -16
- package/dist/facade.js +16 -16
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/parser.cjs +90 -1
- package/dist/parser.d.cts +280 -7
- package/dist/parser.d.ts +280 -7
- package/dist/parser.js +90 -2
- package/dist/valueparser.cjs +1 -1
- package/dist/valueparser.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
@optique/core
|
|
2
2
|
=============
|
|
3
3
|
|
|
4
|
-
> [!
|
|
5
|
-
>
|
|
6
|
-
> Expect breaking changes as we refine the API and features.
|
|
4
|
+
> [!WARNING]
|
|
5
|
+
> The API is stabilizing, but may change before the 1.0 release.
|
|
7
6
|
|
|
8
7
|
The core package of Optique which provides the shared types and parser
|
|
9
8
|
combinators. It is designed to be used in universal JavaScript runtimes,
|
package/dist/facade.cjs
CHANGED
|
@@ -73,7 +73,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
73
73
|
}), require_parser.merge(require_parser.object({
|
|
74
74
|
help: require_parser.constant(false),
|
|
75
75
|
version: require_parser.constant(true)
|
|
76
|
-
}), versionOption)) : help === "none" && version === "both" ? require_parser.longestMatch(require_parser.object({
|
|
76
|
+
}), require_parser.object({ versionFlag: versionOption }))) : help === "none" && version === "both" ? require_parser.longestMatch(require_parser.object({
|
|
77
77
|
help: require_parser.constant(false),
|
|
78
78
|
version: require_parser.constant(true),
|
|
79
79
|
result: versionCommand
|
|
@@ -84,7 +84,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
84
84
|
}), require_parser.merge(require_parser.object({
|
|
85
85
|
help: require_parser.constant(false),
|
|
86
86
|
version: require_parser.constant(true)
|
|
87
|
-
}), versionOption)) : help === "command" && version === "none" ? require_parser.longestMatch(require_parser.object({
|
|
87
|
+
}), require_parser.object({ versionFlag: versionOption }))) : help === "command" && version === "none" ? require_parser.longestMatch(require_parser.object({
|
|
88
88
|
help: require_parser.constant(true),
|
|
89
89
|
version: require_parser.constant(false),
|
|
90
90
|
commands: helpCommand
|
|
@@ -115,7 +115,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
115
115
|
}), require_parser.merge(require_parser.object({
|
|
116
116
|
help: require_parser.constant(false),
|
|
117
117
|
version: require_parser.constant(true)
|
|
118
|
-
}), versionOption)) : help === "command" && version === "both" ? require_parser.longestMatch(require_parser.object({
|
|
118
|
+
}), require_parser.object({ versionFlag: versionOption }))) : help === "command" && version === "both" ? require_parser.longestMatch(require_parser.object({
|
|
119
119
|
help: require_parser.constant(true),
|
|
120
120
|
version: require_parser.constant(false),
|
|
121
121
|
commands: helpCommand
|
|
@@ -130,7 +130,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
130
130
|
}), require_parser.merge(require_parser.object({
|
|
131
131
|
help: require_parser.constant(false),
|
|
132
132
|
version: require_parser.constant(true)
|
|
133
|
-
}), versionOption)) : help === "option" && version === "none" ? require_parser.longestMatch(require_parser.object({
|
|
133
|
+
}), require_parser.object({ versionFlag: versionOption }))) : help === "option" && version === "none" ? require_parser.longestMatch(require_parser.object({
|
|
134
134
|
help: require_parser.constant(false),
|
|
135
135
|
version: require_parser.constant(false),
|
|
136
136
|
result: parser
|
|
@@ -138,7 +138,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
138
138
|
help: require_parser.constant(true),
|
|
139
139
|
version: require_parser.constant(false),
|
|
140
140
|
commands: require_parser.constant([])
|
|
141
|
-
}), helpOption)) : help === "option" && version === "command" ? require_parser.longestMatch(require_parser.object({
|
|
141
|
+
}), require_parser.object({ helpFlag: helpOption }))) : help === "option" && version === "command" ? require_parser.longestMatch(require_parser.object({
|
|
142
142
|
help: require_parser.constant(false),
|
|
143
143
|
version: require_parser.constant(true),
|
|
144
144
|
result: versionCommand
|
|
@@ -150,10 +150,10 @@ function run(parser, programName, args, options = {}) {
|
|
|
150
150
|
help: require_parser.constant(true),
|
|
151
151
|
version: require_parser.constant(false),
|
|
152
152
|
commands: require_parser.constant([])
|
|
153
|
-
}), helpOption)) : help === "option" && version === "option" ? require_parser.longestMatch(require_parser.merge(require_parser.object({
|
|
153
|
+
}), require_parser.object({ helpFlag: helpOption }))) : help === "option" && version === "option" ? require_parser.longestMatch(require_parser.merge(require_parser.object({
|
|
154
154
|
help: require_parser.constant(false),
|
|
155
155
|
version: require_parser.constant(true)
|
|
156
|
-
}), versionOption), require_parser.object({
|
|
156
|
+
}), require_parser.object({ versionFlag: versionOption })), require_parser.object({
|
|
157
157
|
help: require_parser.constant(false),
|
|
158
158
|
version: require_parser.constant(false),
|
|
159
159
|
result: parser
|
|
@@ -161,10 +161,10 @@ function run(parser, programName, args, options = {}) {
|
|
|
161
161
|
help: require_parser.constant(true),
|
|
162
162
|
version: require_parser.constant(false),
|
|
163
163
|
commands: require_parser.constant([])
|
|
164
|
-
}), helpOption)) : help === "option" && version === "both" ? require_parser.longestMatch(require_parser.merge(require_parser.object({
|
|
164
|
+
}), require_parser.object({ helpFlag: helpOption }))) : help === "option" && version === "both" ? require_parser.longestMatch(require_parser.merge(require_parser.object({
|
|
165
165
|
help: require_parser.constant(false),
|
|
166
166
|
version: require_parser.constant(true)
|
|
167
|
-
}), versionOption), require_parser.object({
|
|
167
|
+
}), require_parser.object({ versionFlag: versionOption })), require_parser.object({
|
|
168
168
|
help: require_parser.constant(false),
|
|
169
169
|
version: require_parser.constant(true),
|
|
170
170
|
result: versionCommand
|
|
@@ -176,7 +176,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
176
176
|
help: require_parser.constant(true),
|
|
177
177
|
version: require_parser.constant(false),
|
|
178
178
|
commands: require_parser.constant([])
|
|
179
|
-
}), helpOption)) : help === "both" && version === "none" ? require_parser.longestMatch(require_parser.object({
|
|
179
|
+
}), require_parser.object({ helpFlag: helpOption }))) : help === "both" && version === "none" ? require_parser.longestMatch(require_parser.object({
|
|
180
180
|
help: require_parser.constant(false),
|
|
181
181
|
version: require_parser.constant(false),
|
|
182
182
|
result: parser
|
|
@@ -188,7 +188,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
188
188
|
help: require_parser.constant(true),
|
|
189
189
|
version: require_parser.constant(false),
|
|
190
190
|
commands: require_parser.constant([])
|
|
191
|
-
}), helpOption)) : help === "both" && version === "command" ? require_parser.longestMatch(require_parser.object({
|
|
191
|
+
}), require_parser.object({ helpFlag: helpOption }))) : help === "both" && version === "command" ? require_parser.longestMatch(require_parser.object({
|
|
192
192
|
help: require_parser.constant(true),
|
|
193
193
|
version: require_parser.constant(false),
|
|
194
194
|
commands: helpCommand
|
|
@@ -204,10 +204,10 @@ function run(parser, programName, args, options = {}) {
|
|
|
204
204
|
help: require_parser.constant(true),
|
|
205
205
|
version: require_parser.constant(false),
|
|
206
206
|
commands: require_parser.constant([])
|
|
207
|
-
}), helpOption)) : help === "both" && version === "option" ? require_parser.longestMatch(require_parser.merge(require_parser.object({
|
|
207
|
+
}), require_parser.object({ helpFlag: helpOption }))) : help === "both" && version === "option" ? require_parser.longestMatch(require_parser.merge(require_parser.object({
|
|
208
208
|
help: require_parser.constant(false),
|
|
209
209
|
version: require_parser.constant(true)
|
|
210
|
-
}), versionOption), require_parser.object({
|
|
210
|
+
}), require_parser.object({ versionFlag: versionOption })), require_parser.object({
|
|
211
211
|
help: require_parser.constant(true),
|
|
212
212
|
version: require_parser.constant(false),
|
|
213
213
|
commands: helpCommand
|
|
@@ -219,10 +219,10 @@ function run(parser, programName, args, options = {}) {
|
|
|
219
219
|
help: require_parser.constant(true),
|
|
220
220
|
version: require_parser.constant(false),
|
|
221
221
|
commands: require_parser.constant([])
|
|
222
|
-
}), helpOption)) : require_parser.longestMatch(require_parser.merge(require_parser.object({
|
|
222
|
+
}), require_parser.object({ helpFlag: helpOption }))) : require_parser.longestMatch(require_parser.merge(require_parser.object({
|
|
223
223
|
help: require_parser.constant(false),
|
|
224
224
|
version: require_parser.constant(true)
|
|
225
|
-
}), versionOption), require_parser.object({
|
|
225
|
+
}), require_parser.object({ versionFlag: versionOption })), require_parser.object({
|
|
226
226
|
help: require_parser.constant(false),
|
|
227
227
|
version: require_parser.constant(true),
|
|
228
228
|
result: versionCommand
|
|
@@ -238,7 +238,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
238
238
|
help: require_parser.constant(true),
|
|
239
239
|
version: require_parser.constant(false),
|
|
240
240
|
commands: require_parser.constant([])
|
|
241
|
-
}), helpOption)));
|
|
241
|
+
}), require_parser.object({ helpFlag: helpOption }))));
|
|
242
242
|
let result = require_parser.parse(augmentedParser, args);
|
|
243
243
|
if (result.success && typeof result.value === "object" && result.value != null && "help" in result.value && "version" in result.value) {
|
|
244
244
|
const parsedValue = result.value;
|
package/dist/facade.js
CHANGED
|
@@ -73,7 +73,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
73
73
|
}), merge(object({
|
|
74
74
|
help: constant(false),
|
|
75
75
|
version: constant(true)
|
|
76
|
-
}), versionOption)) : help === "none" && version === "both" ? longestMatch(object({
|
|
76
|
+
}), object({ versionFlag: versionOption }))) : help === "none" && version === "both" ? longestMatch(object({
|
|
77
77
|
help: constant(false),
|
|
78
78
|
version: constant(true),
|
|
79
79
|
result: versionCommand
|
|
@@ -84,7 +84,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
84
84
|
}), merge(object({
|
|
85
85
|
help: constant(false),
|
|
86
86
|
version: constant(true)
|
|
87
|
-
}), versionOption)) : help === "command" && version === "none" ? longestMatch(object({
|
|
87
|
+
}), object({ versionFlag: versionOption }))) : help === "command" && version === "none" ? longestMatch(object({
|
|
88
88
|
help: constant(true),
|
|
89
89
|
version: constant(false),
|
|
90
90
|
commands: helpCommand
|
|
@@ -115,7 +115,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
115
115
|
}), merge(object({
|
|
116
116
|
help: constant(false),
|
|
117
117
|
version: constant(true)
|
|
118
|
-
}), versionOption)) : help === "command" && version === "both" ? longestMatch(object({
|
|
118
|
+
}), object({ versionFlag: versionOption }))) : help === "command" && version === "both" ? longestMatch(object({
|
|
119
119
|
help: constant(true),
|
|
120
120
|
version: constant(false),
|
|
121
121
|
commands: helpCommand
|
|
@@ -130,7 +130,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
130
130
|
}), merge(object({
|
|
131
131
|
help: constant(false),
|
|
132
132
|
version: constant(true)
|
|
133
|
-
}), versionOption)) : help === "option" && version === "none" ? longestMatch(object({
|
|
133
|
+
}), object({ versionFlag: versionOption }))) : help === "option" && version === "none" ? longestMatch(object({
|
|
134
134
|
help: constant(false),
|
|
135
135
|
version: constant(false),
|
|
136
136
|
result: parser
|
|
@@ -138,7 +138,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
138
138
|
help: constant(true),
|
|
139
139
|
version: constant(false),
|
|
140
140
|
commands: constant([])
|
|
141
|
-
}), helpOption)) : help === "option" && version === "command" ? longestMatch(object({
|
|
141
|
+
}), object({ helpFlag: helpOption }))) : help === "option" && version === "command" ? longestMatch(object({
|
|
142
142
|
help: constant(false),
|
|
143
143
|
version: constant(true),
|
|
144
144
|
result: versionCommand
|
|
@@ -150,10 +150,10 @@ function run(parser, programName, args, options = {}) {
|
|
|
150
150
|
help: constant(true),
|
|
151
151
|
version: constant(false),
|
|
152
152
|
commands: constant([])
|
|
153
|
-
}), helpOption)) : help === "option" && version === "option" ? longestMatch(merge(object({
|
|
153
|
+
}), object({ helpFlag: helpOption }))) : help === "option" && version === "option" ? longestMatch(merge(object({
|
|
154
154
|
help: constant(false),
|
|
155
155
|
version: constant(true)
|
|
156
|
-
}), versionOption), object({
|
|
156
|
+
}), object({ versionFlag: versionOption })), object({
|
|
157
157
|
help: constant(false),
|
|
158
158
|
version: constant(false),
|
|
159
159
|
result: parser
|
|
@@ -161,10 +161,10 @@ function run(parser, programName, args, options = {}) {
|
|
|
161
161
|
help: constant(true),
|
|
162
162
|
version: constant(false),
|
|
163
163
|
commands: constant([])
|
|
164
|
-
}), helpOption)) : help === "option" && version === "both" ? longestMatch(merge(object({
|
|
164
|
+
}), object({ helpFlag: helpOption }))) : help === "option" && version === "both" ? longestMatch(merge(object({
|
|
165
165
|
help: constant(false),
|
|
166
166
|
version: constant(true)
|
|
167
|
-
}), versionOption), object({
|
|
167
|
+
}), object({ versionFlag: versionOption })), object({
|
|
168
168
|
help: constant(false),
|
|
169
169
|
version: constant(true),
|
|
170
170
|
result: versionCommand
|
|
@@ -176,7 +176,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
176
176
|
help: constant(true),
|
|
177
177
|
version: constant(false),
|
|
178
178
|
commands: constant([])
|
|
179
|
-
}), helpOption)) : help === "both" && version === "none" ? longestMatch(object({
|
|
179
|
+
}), object({ helpFlag: helpOption }))) : help === "both" && version === "none" ? longestMatch(object({
|
|
180
180
|
help: constant(false),
|
|
181
181
|
version: constant(false),
|
|
182
182
|
result: parser
|
|
@@ -188,7 +188,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
188
188
|
help: constant(true),
|
|
189
189
|
version: constant(false),
|
|
190
190
|
commands: constant([])
|
|
191
|
-
}), helpOption)) : help === "both" && version === "command" ? longestMatch(object({
|
|
191
|
+
}), object({ helpFlag: helpOption }))) : help === "both" && version === "command" ? longestMatch(object({
|
|
192
192
|
help: constant(true),
|
|
193
193
|
version: constant(false),
|
|
194
194
|
commands: helpCommand
|
|
@@ -204,10 +204,10 @@ function run(parser, programName, args, options = {}) {
|
|
|
204
204
|
help: constant(true),
|
|
205
205
|
version: constant(false),
|
|
206
206
|
commands: constant([])
|
|
207
|
-
}), helpOption)) : help === "both" && version === "option" ? longestMatch(merge(object({
|
|
207
|
+
}), object({ helpFlag: helpOption }))) : help === "both" && version === "option" ? longestMatch(merge(object({
|
|
208
208
|
help: constant(false),
|
|
209
209
|
version: constant(true)
|
|
210
|
-
}), versionOption), object({
|
|
210
|
+
}), object({ versionFlag: versionOption })), object({
|
|
211
211
|
help: constant(true),
|
|
212
212
|
version: constant(false),
|
|
213
213
|
commands: helpCommand
|
|
@@ -219,10 +219,10 @@ function run(parser, programName, args, options = {}) {
|
|
|
219
219
|
help: constant(true),
|
|
220
220
|
version: constant(false),
|
|
221
221
|
commands: constant([])
|
|
222
|
-
}), helpOption)) : longestMatch(merge(object({
|
|
222
|
+
}), object({ helpFlag: helpOption }))) : longestMatch(merge(object({
|
|
223
223
|
help: constant(false),
|
|
224
224
|
version: constant(true)
|
|
225
|
-
}), versionOption), object({
|
|
225
|
+
}), object({ versionFlag: versionOption })), object({
|
|
226
226
|
help: constant(false),
|
|
227
227
|
version: constant(true),
|
|
228
228
|
result: versionCommand
|
|
@@ -238,7 +238,7 @@ function run(parser, programName, args, options = {}) {
|
|
|
238
238
|
help: constant(true),
|
|
239
239
|
version: constant(false),
|
|
240
240
|
commands: constant([])
|
|
241
|
-
}), helpOption)));
|
|
241
|
+
}), object({ helpFlag: helpOption }))));
|
|
242
242
|
let result = parse(augmentedParser, args);
|
|
243
243
|
if (result.success && typeof result.value === "object" && result.value != null && "help" in result.value && "version" in result.value) {
|
|
244
244
|
const parsedValue = result.value;
|
package/dist/index.cjs
CHANGED
|
@@ -18,6 +18,7 @@ exports.formatMessage = require_message.formatMessage;
|
|
|
18
18
|
exports.formatUsage = require_usage.formatUsage;
|
|
19
19
|
exports.formatUsageTerm = require_usage.formatUsageTerm;
|
|
20
20
|
exports.getDocPage = require_parser.getDocPage;
|
|
21
|
+
exports.group = require_parser.group;
|
|
21
22
|
exports.integer = require_valueparser.integer;
|
|
22
23
|
exports.isValueParser = require_valueparser.isValueParser;
|
|
23
24
|
exports.locale = require_valueparser.locale;
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,6 @@ import { Message, MessageFormatOptions, MessageTerm, formatMessage, message, met
|
|
|
2
2
|
import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.cjs";
|
|
3
3
|
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, formatDocPage } from "./doc.cjs";
|
|
4
4
|
import { ChoiceOptions, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.cjs";
|
|
5
|
-
import { ArgumentOptions, CommandOptions, DocState, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, longestMatch, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault } from "./parser.cjs";
|
|
5
|
+
import { ArgumentOptions, CommandOptions, DocState, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, group, longestMatch, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault } from "./parser.cjs";
|
|
6
6
|
import { RunError, RunOptions, run } from "./facade.cjs";
|
|
7
|
-
export { ArgumentOptions, ChoiceOptions, CommandOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, FlagOptions, FloatOptions, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, Message, MessageFormatOptions, MessageTerm, MultipleOptions, OptionName, OptionOptions, Parser, ParserContext, ParserResult, Result, RunError, RunOptions, StringOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, argument, choice, command, concat, constant, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, integer, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, object, option, optionName, optionNames, optional, or, parse, run, string, text, tuple, url, uuid, value, values, withDefault };
|
|
7
|
+
export { ArgumentOptions, ChoiceOptions, CommandOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, FlagOptions, FloatOptions, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, Message, MessageFormatOptions, MessageTerm, MultipleOptions, OptionName, OptionOptions, Parser, ParserContext, ParserResult, Result, RunError, RunOptions, StringOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, argument, choice, command, concat, constant, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, group, integer, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, object, option, optionName, optionNames, optional, or, parse, run, string, text, tuple, url, uuid, value, values, withDefault };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { Message, MessageFormatOptions, MessageTerm, formatMessage, message, met
|
|
|
2
2
|
import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
|
|
3
3
|
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, formatDocPage } from "./doc.js";
|
|
4
4
|
import { ChoiceOptions, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
|
|
5
|
-
import { ArgumentOptions, CommandOptions, DocState, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, longestMatch, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault } from "./parser.js";
|
|
5
|
+
import { ArgumentOptions, CommandOptions, DocState, FlagOptions, InferValue, MultipleOptions, OptionOptions, Parser, ParserContext, ParserResult, Result, argument, command, concat, constant, flag, getDocPage, group, longestMatch, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault } from "./parser.js";
|
|
6
6
|
import { RunError, RunOptions, run } from "./facade.js";
|
|
7
|
-
export { ArgumentOptions, ChoiceOptions, CommandOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, FlagOptions, FloatOptions, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, Message, MessageFormatOptions, MessageTerm, MultipleOptions, OptionName, OptionOptions, Parser, ParserContext, ParserResult, Result, RunError, RunOptions, StringOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, argument, choice, command, concat, constant, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, integer, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, object, option, optionName, optionNames, optional, or, parse, run, string, text, tuple, url, uuid, value, values, withDefault };
|
|
7
|
+
export { ArgumentOptions, ChoiceOptions, CommandOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, FlagOptions, FloatOptions, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, Message, MessageFormatOptions, MessageTerm, MultipleOptions, OptionName, OptionOptions, Parser, ParserContext, ParserResult, Result, RunError, RunOptions, StringOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, argument, choice, command, concat, constant, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, group, integer, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, object, option, optionName, optionNames, optional, or, parse, run, string, text, tuple, url, uuid, value, values, withDefault };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { formatMessage, message, metavar, optionName, optionNames, text, value,
|
|
|
2
2
|
import { formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
|
|
3
3
|
import { formatDocPage } from "./doc.js";
|
|
4
4
|
import { choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
|
|
5
|
-
import { argument, command, concat, constant, flag, getDocPage, longestMatch, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault } from "./parser.js";
|
|
5
|
+
import { argument, command, concat, constant, flag, getDocPage, group, longestMatch, map, merge, multiple, object, option, optional, or, parse, tuple, withDefault } from "./parser.js";
|
|
6
6
|
import { RunError, run } from "./facade.js";
|
|
7
7
|
|
|
8
|
-
export { RunError, argument, choice, command, concat, constant, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, integer, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, object, option, optionName, optionNames, optional, or, parse, run, string, text, tuple, url, uuid, value, values, withDefault };
|
|
8
|
+
export { RunError, argument, choice, command, concat, constant, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, group, integer, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, object, option, optionName, optionNames, optional, or, parse, run, string, text, tuple, url, uuid, value, values, withDefault };
|
package/dist/parser.cjs
CHANGED
|
@@ -1111,7 +1111,9 @@ function longestMatch(...parsers) {
|
|
|
1111
1111
|
}
|
|
1112
1112
|
};
|
|
1113
1113
|
}
|
|
1114
|
-
function merge(...
|
|
1114
|
+
function merge(...args) {
|
|
1115
|
+
const label = typeof args[0] === "string" ? args[0] : void 0;
|
|
1116
|
+
let parsers = typeof args[0] === "string" ? args.slice(1) : args;
|
|
1115
1117
|
parsers = parsers.toSorted((a, b) => b.priority - a.priority);
|
|
1116
1118
|
const initialState = {};
|
|
1117
1119
|
for (const parser of parsers) if (parser.initialState && typeof parser.initialState === "object") for (const field in parser.initialState) initialState[field] = parser.initialState[field];
|
|
@@ -1204,6 +1206,17 @@ function merge(...parsers) {
|
|
|
1204
1206
|
if (fragment.title == null) entries.push(...fragment.entries);
|
|
1205
1207
|
else sections.push(fragment);
|
|
1206
1208
|
}
|
|
1209
|
+
if (label) {
|
|
1210
|
+
const labeledSection = {
|
|
1211
|
+
title: label,
|
|
1212
|
+
entries
|
|
1213
|
+
};
|
|
1214
|
+
sections.push(labeledSection);
|
|
1215
|
+
return { fragments: sections.map((s) => ({
|
|
1216
|
+
...s,
|
|
1217
|
+
type: "section"
|
|
1218
|
+
})) };
|
|
1219
|
+
}
|
|
1207
1220
|
return { fragments: [...sections.map((s) => ({
|
|
1208
1221
|
...s,
|
|
1209
1222
|
type: "section"
|
|
@@ -1479,6 +1492,81 @@ function parse(parser, args) {
|
|
|
1479
1492
|
};
|
|
1480
1493
|
}
|
|
1481
1494
|
/**
|
|
1495
|
+
* Wraps a parser with a group label for documentation purposes.
|
|
1496
|
+
*
|
|
1497
|
+
* The `group()` function is a documentation-only wrapper that applies a label
|
|
1498
|
+
* to any parser for help text organization. This allows you to use clean code
|
|
1499
|
+
* structure with combinators like {@link merge} while maintaining well-organized
|
|
1500
|
+
* help text through group labeling.
|
|
1501
|
+
*
|
|
1502
|
+
* The wrapped parser has identical parsing behavior but generates documentation
|
|
1503
|
+
* fragments wrapped in a labeled section. This is particularly useful when
|
|
1504
|
+
* combining parsers using {@link merge}—you can wrap the merged result with
|
|
1505
|
+
* `group()` to add a section header in help output.
|
|
1506
|
+
*
|
|
1507
|
+
* @example
|
|
1508
|
+
* ```typescript
|
|
1509
|
+
* const apiOptions = merge(
|
|
1510
|
+
* object({ endpoint: option("--endpoint", string()) }),
|
|
1511
|
+
* object({ timeout: option("--timeout", integer()) })
|
|
1512
|
+
* );
|
|
1513
|
+
*
|
|
1514
|
+
* const groupedApiOptions = group("API Options", apiOptions);
|
|
1515
|
+
* // Now produces a labeled "API Options" section in help text
|
|
1516
|
+
* ```
|
|
1517
|
+
*
|
|
1518
|
+
* @example
|
|
1519
|
+
* ```typescript
|
|
1520
|
+
* // Can be used with any parser, not just merge()
|
|
1521
|
+
* const verboseGroup = group("Verbosity", object({
|
|
1522
|
+
* verbose: option("-v", "--verbose"),
|
|
1523
|
+
* quiet: option("-q", "--quiet")
|
|
1524
|
+
* }));
|
|
1525
|
+
* ```
|
|
1526
|
+
*
|
|
1527
|
+
* @template TValue The value type of the wrapped parser.
|
|
1528
|
+
* @template TState The state type of the wrapped parser.
|
|
1529
|
+
* @param label A descriptive label for this parser group, used for
|
|
1530
|
+
* documentation and help text organization.
|
|
1531
|
+
* @param parser The parser to wrap with a group label.
|
|
1532
|
+
* @returns A new parser that behaves identically to the input parser
|
|
1533
|
+
* but generates documentation within a labeled section.
|
|
1534
|
+
* @since 0.4.0
|
|
1535
|
+
*/
|
|
1536
|
+
function group(label, parser) {
|
|
1537
|
+
return {
|
|
1538
|
+
$valueType: parser.$valueType,
|
|
1539
|
+
$stateType: parser.$stateType,
|
|
1540
|
+
priority: parser.priority,
|
|
1541
|
+
usage: parser.usage,
|
|
1542
|
+
initialState: parser.initialState,
|
|
1543
|
+
parse: (context) => parser.parse(context),
|
|
1544
|
+
complete: (state) => parser.complete(state),
|
|
1545
|
+
getDocFragments: (state, defaultValue) => {
|
|
1546
|
+
const { description, fragments } = parser.getDocFragments(state, defaultValue);
|
|
1547
|
+
const allEntries = [];
|
|
1548
|
+
const titledSections = [];
|
|
1549
|
+
for (const fragment of fragments) if (fragment.type === "entry") allEntries.push(fragment);
|
|
1550
|
+
else if (fragment.type === "section") if (fragment.title) titledSections.push(fragment);
|
|
1551
|
+
else allEntries.push(...fragment.entries);
|
|
1552
|
+
const labeledSection = {
|
|
1553
|
+
title: label,
|
|
1554
|
+
entries: allEntries
|
|
1555
|
+
};
|
|
1556
|
+
return {
|
|
1557
|
+
description,
|
|
1558
|
+
fragments: [...titledSections.map((s) => ({
|
|
1559
|
+
...s,
|
|
1560
|
+
type: "section"
|
|
1561
|
+
})), {
|
|
1562
|
+
type: "section",
|
|
1563
|
+
...labeledSection
|
|
1564
|
+
}]
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
/**
|
|
1482
1570
|
* Generates a documentation page for a parser based on its current state after
|
|
1483
1571
|
* attempting to parse the provided arguments. This function is useful for
|
|
1484
1572
|
* creating help documentation that reflects the current parsing context.
|
|
@@ -1563,6 +1651,7 @@ exports.concat = concat;
|
|
|
1563
1651
|
exports.constant = constant;
|
|
1564
1652
|
exports.flag = flag;
|
|
1565
1653
|
exports.getDocPage = getDocPage;
|
|
1654
|
+
exports.group = group;
|
|
1566
1655
|
exports.longestMatch = longestMatch;
|
|
1567
1656
|
exports.map = map;
|
|
1568
1657
|
exports.merge = merge;
|