@optique/core 0.7.10 → 0.7.12
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/constructs.cjs +9 -0
- package/dist/constructs.js +9 -0
- package/dist/doc.d.cts +6 -0
- package/dist/doc.d.ts +6 -0
- package/dist/facade.cjs +48 -3
- package/dist/facade.js +48 -3
- package/dist/parser.cjs +2 -1
- package/dist/parser.js +2 -1
- package/dist/primitives.cjs +1 -0
- package/dist/primitives.js +1 -0
- package/package.json +1 -1
package/dist/constructs.cjs
CHANGED
|
@@ -193,7 +193,9 @@ function or(...args) {
|
|
|
193
193
|
});
|
|
194
194
|
},
|
|
195
195
|
getDocFragments(state, _defaultValue) {
|
|
196
|
+
let brief;
|
|
196
197
|
let description;
|
|
198
|
+
let footer;
|
|
197
199
|
let fragments;
|
|
198
200
|
if (state.kind === "unavailable" || state.state == null) fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }, void 0).fragments);
|
|
199
201
|
else {
|
|
@@ -203,7 +205,9 @@ function or(...args) {
|
|
|
203
205
|
state: parserResult.next.state
|
|
204
206
|
} : { kind: "unavailable" };
|
|
205
207
|
const docFragments = parsers[index].getDocFragments(innerState, void 0);
|
|
208
|
+
brief = docFragments.brief;
|
|
206
209
|
description = docFragments.description;
|
|
210
|
+
footer = docFragments.footer;
|
|
207
211
|
fragments = docFragments.fragments;
|
|
208
212
|
}
|
|
209
213
|
const entries = fragments.filter((f) => f.type === "entry");
|
|
@@ -214,7 +218,9 @@ function or(...args) {
|
|
|
214
218
|
else sections.push(fragment);
|
|
215
219
|
}
|
|
216
220
|
return {
|
|
221
|
+
brief,
|
|
217
222
|
description,
|
|
223
|
+
footer,
|
|
218
224
|
fragments: [...sections.map((s) => ({
|
|
219
225
|
...s,
|
|
220
226
|
type: "section"
|
|
@@ -337,6 +343,7 @@ function longestMatch(...args) {
|
|
|
337
343
|
});
|
|
338
344
|
},
|
|
339
345
|
getDocFragments(state, _defaultValue) {
|
|
346
|
+
let brief;
|
|
340
347
|
let description;
|
|
341
348
|
let footer;
|
|
342
349
|
let fragments;
|
|
@@ -348,12 +355,14 @@ function longestMatch(...args) {
|
|
|
348
355
|
kind: "available",
|
|
349
356
|
state: result.next.state
|
|
350
357
|
});
|
|
358
|
+
brief = docResult.brief;
|
|
351
359
|
description = docResult.description;
|
|
352
360
|
footer = docResult.footer;
|
|
353
361
|
fragments = docResult.fragments;
|
|
354
362
|
} else fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }).fragments);
|
|
355
363
|
}
|
|
356
364
|
return {
|
|
365
|
+
brief,
|
|
357
366
|
description,
|
|
358
367
|
fragments,
|
|
359
368
|
footer
|
package/dist/constructs.js
CHANGED
|
@@ -193,7 +193,9 @@ function or(...args) {
|
|
|
193
193
|
});
|
|
194
194
|
},
|
|
195
195
|
getDocFragments(state, _defaultValue) {
|
|
196
|
+
let brief;
|
|
196
197
|
let description;
|
|
198
|
+
let footer;
|
|
197
199
|
let fragments;
|
|
198
200
|
if (state.kind === "unavailable" || state.state == null) fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }, void 0).fragments);
|
|
199
201
|
else {
|
|
@@ -203,7 +205,9 @@ function or(...args) {
|
|
|
203
205
|
state: parserResult.next.state
|
|
204
206
|
} : { kind: "unavailable" };
|
|
205
207
|
const docFragments = parsers[index].getDocFragments(innerState, void 0);
|
|
208
|
+
brief = docFragments.brief;
|
|
206
209
|
description = docFragments.description;
|
|
210
|
+
footer = docFragments.footer;
|
|
207
211
|
fragments = docFragments.fragments;
|
|
208
212
|
}
|
|
209
213
|
const entries = fragments.filter((f) => f.type === "entry");
|
|
@@ -214,7 +218,9 @@ function or(...args) {
|
|
|
214
218
|
else sections.push(fragment);
|
|
215
219
|
}
|
|
216
220
|
return {
|
|
221
|
+
brief,
|
|
217
222
|
description,
|
|
223
|
+
footer,
|
|
218
224
|
fragments: [...sections.map((s) => ({
|
|
219
225
|
...s,
|
|
220
226
|
type: "section"
|
|
@@ -337,6 +343,7 @@ function longestMatch(...args) {
|
|
|
337
343
|
});
|
|
338
344
|
},
|
|
339
345
|
getDocFragments(state, _defaultValue) {
|
|
346
|
+
let brief;
|
|
340
347
|
let description;
|
|
341
348
|
let footer;
|
|
342
349
|
let fragments;
|
|
@@ -348,12 +355,14 @@ function longestMatch(...args) {
|
|
|
348
355
|
kind: "available",
|
|
349
356
|
state: result.next.state
|
|
350
357
|
});
|
|
358
|
+
brief = docResult.brief;
|
|
351
359
|
description = docResult.description;
|
|
352
360
|
footer = docResult.footer;
|
|
353
361
|
fragments = docResult.fragments;
|
|
354
362
|
} else fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }).fragments);
|
|
355
363
|
}
|
|
356
364
|
return {
|
|
365
|
+
brief,
|
|
357
366
|
description,
|
|
358
367
|
fragments,
|
|
359
368
|
footer
|
package/dist/doc.d.cts
CHANGED
|
@@ -60,6 +60,12 @@ type DocFragment = {
|
|
|
60
60
|
* a final document page.
|
|
61
61
|
*/
|
|
62
62
|
interface DocFragments {
|
|
63
|
+
/**
|
|
64
|
+
* An optional brief that provides a short summary for the collection
|
|
65
|
+
* of fragments.
|
|
66
|
+
* @since 0.7.12
|
|
67
|
+
*/
|
|
68
|
+
readonly brief?: Message;
|
|
63
69
|
/**
|
|
64
70
|
* An optional description that applies to the entire collection of fragments.
|
|
65
71
|
*/
|
package/dist/doc.d.ts
CHANGED
|
@@ -60,6 +60,12 @@ type DocFragment = {
|
|
|
60
60
|
* a final document page.
|
|
61
61
|
*/
|
|
62
62
|
interface DocFragments {
|
|
63
|
+
/**
|
|
64
|
+
* An optional brief that provides a short summary for the collection
|
|
65
|
+
* of fragments.
|
|
66
|
+
* @since 0.7.12
|
|
67
|
+
*/
|
|
68
|
+
readonly brief?: Message;
|
|
63
69
|
/**
|
|
64
70
|
* An optional description that applies to the entire collection of fragments.
|
|
65
71
|
*/
|
package/dist/facade.cjs
CHANGED
|
@@ -515,14 +515,59 @@ function run(parser, programName, args, options = {}) {
|
|
|
515
515
|
else if (commandParsers.length === 2) helpGeneratorParser = require_constructs.longestMatch(commandParsers[0], commandParsers[1]);
|
|
516
516
|
else helpGeneratorParser = require_constructs.longestMatch(...commandParsers);
|
|
517
517
|
}
|
|
518
|
+
if (classified.commands.length > 0) {
|
|
519
|
+
let validationContext = {
|
|
520
|
+
buffer: [...classified.commands],
|
|
521
|
+
optionsTerminated: false,
|
|
522
|
+
state: helpGeneratorParser.initialState,
|
|
523
|
+
usage: helpGeneratorParser.usage
|
|
524
|
+
};
|
|
525
|
+
let commandsValid = true;
|
|
526
|
+
let validationError;
|
|
527
|
+
while (validationContext.buffer.length > 0) {
|
|
528
|
+
const stepResult = helpGeneratorParser.parse(validationContext);
|
|
529
|
+
if (!stepResult.success) {
|
|
530
|
+
commandsValid = false;
|
|
531
|
+
validationError = stepResult.error;
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
if (stepResult.consumed.length < 1) {
|
|
535
|
+
commandsValid = false;
|
|
536
|
+
validationError = require_message.message`Unexpected option or subcommand: ${require_message.optionName(validationContext.buffer[0])}.`;
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
validationContext = {
|
|
540
|
+
...validationContext,
|
|
541
|
+
buffer: stepResult.next.buffer,
|
|
542
|
+
optionsTerminated: stepResult.next.optionsTerminated,
|
|
543
|
+
state: stepResult.next.state,
|
|
544
|
+
usage: stepResult.next.usage ?? validationContext.usage
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
if (!commandsValid && validationError != null) {
|
|
548
|
+
stderr(`Usage: ${indentLines(require_usage.formatUsage(programName, augmentedParser.usage, {
|
|
549
|
+
colors,
|
|
550
|
+
maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
|
|
551
|
+
expandCommands: true
|
|
552
|
+
}), 7)}`);
|
|
553
|
+
const errorMessage = require_message.formatMessage(validationError, {
|
|
554
|
+
colors,
|
|
555
|
+
quotes: !colors
|
|
556
|
+
});
|
|
557
|
+
stderr(`Error: ${errorMessage}`);
|
|
558
|
+
return onError(1);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
518
561
|
const doc = require_parser.getDocPage(helpGeneratorParser, classified.commands);
|
|
519
562
|
if (doc != null) {
|
|
520
563
|
const isMetaCommandHelp = (completionName === "singular" || completionName === "both" ? requestedCommand === "completion" : false) || (completionName === "plural" || completionName === "both" ? requestedCommand === "completions" : false) || requestedCommand === "help" || requestedCommand === "version";
|
|
564
|
+
const isSubcommandHelp = classified.commands.length > 0;
|
|
565
|
+
const shouldOverride = !isMetaCommandHelp && !isSubcommandHelp;
|
|
521
566
|
const augmentedDoc = {
|
|
522
567
|
...doc,
|
|
523
|
-
brief:
|
|
524
|
-
description:
|
|
525
|
-
footer:
|
|
568
|
+
brief: shouldOverride ? brief ?? doc.brief : doc.brief ?? brief,
|
|
569
|
+
description: shouldOverride ? description ?? doc.description : doc.description ?? description,
|
|
570
|
+
footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
|
|
526
571
|
};
|
|
527
572
|
stdout(require_doc.formatDocPage(programName, augmentedDoc, {
|
|
528
573
|
colors,
|
package/dist/facade.js
CHANGED
|
@@ -515,14 +515,59 @@ function run(parser, programName, args, options = {}) {
|
|
|
515
515
|
else if (commandParsers.length === 2) helpGeneratorParser = longestMatch(commandParsers[0], commandParsers[1]);
|
|
516
516
|
else helpGeneratorParser = longestMatch(...commandParsers);
|
|
517
517
|
}
|
|
518
|
+
if (classified.commands.length > 0) {
|
|
519
|
+
let validationContext = {
|
|
520
|
+
buffer: [...classified.commands],
|
|
521
|
+
optionsTerminated: false,
|
|
522
|
+
state: helpGeneratorParser.initialState,
|
|
523
|
+
usage: helpGeneratorParser.usage
|
|
524
|
+
};
|
|
525
|
+
let commandsValid = true;
|
|
526
|
+
let validationError;
|
|
527
|
+
while (validationContext.buffer.length > 0) {
|
|
528
|
+
const stepResult = helpGeneratorParser.parse(validationContext);
|
|
529
|
+
if (!stepResult.success) {
|
|
530
|
+
commandsValid = false;
|
|
531
|
+
validationError = stepResult.error;
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
if (stepResult.consumed.length < 1) {
|
|
535
|
+
commandsValid = false;
|
|
536
|
+
validationError = message`Unexpected option or subcommand: ${optionName(validationContext.buffer[0])}.`;
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
validationContext = {
|
|
540
|
+
...validationContext,
|
|
541
|
+
buffer: stepResult.next.buffer,
|
|
542
|
+
optionsTerminated: stepResult.next.optionsTerminated,
|
|
543
|
+
state: stepResult.next.state,
|
|
544
|
+
usage: stepResult.next.usage ?? validationContext.usage
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
if (!commandsValid && validationError != null) {
|
|
548
|
+
stderr(`Usage: ${indentLines(formatUsage(programName, augmentedParser.usage, {
|
|
549
|
+
colors,
|
|
550
|
+
maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
|
|
551
|
+
expandCommands: true
|
|
552
|
+
}), 7)}`);
|
|
553
|
+
const errorMessage = formatMessage(validationError, {
|
|
554
|
+
colors,
|
|
555
|
+
quotes: !colors
|
|
556
|
+
});
|
|
557
|
+
stderr(`Error: ${errorMessage}`);
|
|
558
|
+
return onError(1);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
518
561
|
const doc = getDocPage(helpGeneratorParser, classified.commands);
|
|
519
562
|
if (doc != null) {
|
|
520
563
|
const isMetaCommandHelp = (completionName === "singular" || completionName === "both" ? requestedCommand === "completion" : false) || (completionName === "plural" || completionName === "both" ? requestedCommand === "completions" : false) || requestedCommand === "help" || requestedCommand === "version";
|
|
564
|
+
const isSubcommandHelp = classified.commands.length > 0;
|
|
565
|
+
const shouldOverride = !isMetaCommandHelp && !isSubcommandHelp;
|
|
521
566
|
const augmentedDoc = {
|
|
522
567
|
...doc,
|
|
523
|
-
brief:
|
|
524
|
-
description:
|
|
525
|
-
footer:
|
|
568
|
+
brief: shouldOverride ? brief ?? doc.brief : doc.brief ?? brief,
|
|
569
|
+
description: shouldOverride ? description ?? doc.description : doc.description ?? description,
|
|
570
|
+
footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
|
|
526
571
|
};
|
|
527
572
|
stdout(formatDocPage(programName, augmentedDoc, {
|
|
528
573
|
colors,
|
package/dist/parser.cjs
CHANGED
|
@@ -159,7 +159,7 @@ function getDocPage(parser, args = []) {
|
|
|
159
159
|
if (!result.success) break;
|
|
160
160
|
context = result.next;
|
|
161
161
|
} while (context.buffer.length > 0);
|
|
162
|
-
const { description, fragments, footer } = parser.getDocFragments({
|
|
162
|
+
const { brief, description, fragments, footer } = parser.getDocFragments({
|
|
163
163
|
kind: "available",
|
|
164
164
|
state: context.state
|
|
165
165
|
}, void 0);
|
|
@@ -184,6 +184,7 @@ function getDocPage(parser, args = []) {
|
|
|
184
184
|
return {
|
|
185
185
|
usage,
|
|
186
186
|
sections,
|
|
187
|
+
...brief != null && { brief },
|
|
187
188
|
...description != null && { description },
|
|
188
189
|
...footer != null && { footer }
|
|
189
190
|
};
|
package/dist/parser.js
CHANGED
|
@@ -159,7 +159,7 @@ function getDocPage(parser, args = []) {
|
|
|
159
159
|
if (!result.success) break;
|
|
160
160
|
context = result.next;
|
|
161
161
|
} while (context.buffer.length > 0);
|
|
162
|
-
const { description, fragments, footer } = parser.getDocFragments({
|
|
162
|
+
const { brief, description, fragments, footer } = parser.getDocFragments({
|
|
163
163
|
kind: "available",
|
|
164
164
|
state: context.state
|
|
165
165
|
}, void 0);
|
|
@@ -184,6 +184,7 @@ function getDocPage(parser, args = []) {
|
|
|
184
184
|
return {
|
|
185
185
|
usage,
|
|
186
186
|
sections,
|
|
187
|
+
...brief != null && { brief },
|
|
187
188
|
...description != null && { description },
|
|
188
189
|
...footer != null && { footer }
|
|
189
190
|
};
|
package/dist/primitives.cjs
CHANGED
|
@@ -725,6 +725,7 @@ function command(name, parser, options = {}) {
|
|
|
725
725
|
const innerFragments = parser.getDocFragments(innerState, defaultValue);
|
|
726
726
|
return {
|
|
727
727
|
...innerFragments,
|
|
728
|
+
brief: innerFragments.brief ?? options.brief,
|
|
728
729
|
description: innerFragments.description ?? options.description,
|
|
729
730
|
footer: innerFragments.footer ?? options.footer
|
|
730
731
|
};
|
package/dist/primitives.js
CHANGED
|
@@ -725,6 +725,7 @@ function command(name, parser, options = {}) {
|
|
|
725
725
|
const innerFragments = parser.getDocFragments(innerState, defaultValue);
|
|
726
726
|
return {
|
|
727
727
|
...innerFragments,
|
|
728
|
+
brief: innerFragments.brief ?? options.brief,
|
|
728
729
|
description: innerFragments.description ?? options.description,
|
|
729
730
|
footer: innerFragments.footer ?? options.footer
|
|
730
731
|
};
|