@optique/core 0.10.0-dev.360 → 0.10.0-dev.367
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 +63 -12
- package/dist/constructs.js +65 -14
- package/dist/facade.cjs +26 -16
- package/dist/facade.d.cts +77 -41
- package/dist/facade.d.ts +77 -41
- package/dist/facade.js +26 -16
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/suggestion.cjs +1 -0
- package/dist/suggestion.js +1 -1
- package/package.json +1 -1
package/dist/constructs.cjs
CHANGED
|
@@ -6,6 +6,57 @@ const require_suggestion = require('./suggestion.cjs');
|
|
|
6
6
|
|
|
7
7
|
//#region src/constructs.ts
|
|
8
8
|
/**
|
|
9
|
+
* Collects option names and command names that are valid at the current
|
|
10
|
+
* parse position by walking the usage tree. Only "leading" candidates
|
|
11
|
+
* (those reachable before a required positional argument) are collected.
|
|
12
|
+
*/
|
|
13
|
+
function collectLeadingCandidates(terms, optionNames, commandNames) {
|
|
14
|
+
if (!terms || !Array.isArray(terms)) return true;
|
|
15
|
+
for (const term of terms) {
|
|
16
|
+
if (term.type === "option") {
|
|
17
|
+
for (const name of term.names) optionNames.add(name);
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (term.type === "command") {
|
|
21
|
+
commandNames.add(term.name);
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (term.type === "argument") return false;
|
|
25
|
+
if (term.type === "optional") {
|
|
26
|
+
collectLeadingCandidates(term.terms, optionNames, commandNames);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (term.type === "multiple") {
|
|
30
|
+
collectLeadingCandidates(term.terms, optionNames, commandNames);
|
|
31
|
+
if (term.min === 0) continue;
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (term.type === "exclusive") {
|
|
35
|
+
let allAlternativesSkippable = true;
|
|
36
|
+
for (const exclusiveUsage of term.terms) {
|
|
37
|
+
const alternativeSkippable = collectLeadingCandidates(exclusiveUsage, optionNames, commandNames);
|
|
38
|
+
allAlternativesSkippable = allAlternativesSkippable && alternativeSkippable;
|
|
39
|
+
}
|
|
40
|
+
if (allAlternativesSkippable) continue;
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
function createUnexpectedInputErrorWithScopedSuggestions(baseError, invalidInput, parsers, customFormatter) {
|
|
47
|
+
const options = /* @__PURE__ */ new Set();
|
|
48
|
+
const commands = /* @__PURE__ */ new Set();
|
|
49
|
+
for (const parser of parsers) collectLeadingCandidates(parser.usage, options, commands);
|
|
50
|
+
const candidates = new Set([...options, ...commands]);
|
|
51
|
+
const suggestions = require_suggestion.findSimilar(invalidInput, candidates, require_suggestion.DEFAULT_FIND_SIMILAR_OPTIONS);
|
|
52
|
+
const suggestionMsg = customFormatter ? customFormatter(suggestions) : require_suggestion.createSuggestionMessage(suggestions);
|
|
53
|
+
return suggestionMsg.length > 0 ? [
|
|
54
|
+
...baseError,
|
|
55
|
+
require_message.text("\n\n"),
|
|
56
|
+
...suggestionMsg
|
|
57
|
+
] : baseError;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
9
60
|
* Checks if the given token is an option name that requires a value
|
|
10
61
|
* (i.e., has a metavar) within the given usage terms.
|
|
11
62
|
* @param usage The usage terms to search through.
|
|
@@ -200,16 +251,6 @@ function getNoMatchError(options, noMatchContext) {
|
|
|
200
251
|
return customNoMatch ? typeof customNoMatch === "function" ? customNoMatch(noMatchContext) : customNoMatch : generateNoMatchError(noMatchContext);
|
|
201
252
|
}
|
|
202
253
|
/**
|
|
203
|
-
* Creates default error for parse() method when buffer is not empty.
|
|
204
|
-
* Shared by or() and longestMatch().
|
|
205
|
-
* @internal
|
|
206
|
-
*/
|
|
207
|
-
function createUnexpectedInputError(token, usage, options) {
|
|
208
|
-
const defaultMsg = require_message.message`Unexpected option or subcommand: ${require_message.optionName(token)}.`;
|
|
209
|
-
if (options?.errors?.unexpectedInput != null) return typeof options.errors.unexpectedInput === "function" ? options.errors.unexpectedInput(token) : options.errors.unexpectedInput;
|
|
210
|
-
return require_suggestion.createErrorWithSuggestions(defaultMsg, token, usage, "both", options?.errors?.suggestions);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
254
|
* @since 0.5.0
|
|
214
255
|
*/
|
|
215
256
|
function or(...args) {
|
|
@@ -227,7 +268,12 @@ function or(...args) {
|
|
|
227
268
|
const syncParsers = parsers;
|
|
228
269
|
const getInitialError = (context) => ({
|
|
229
270
|
consumed: 0,
|
|
230
|
-
error: context.buffer.length < 1 ? getNoMatchError(options, noMatchContext) :
|
|
271
|
+
error: context.buffer.length < 1 ? getNoMatchError(options, noMatchContext) : (() => {
|
|
272
|
+
const token = context.buffer[0];
|
|
273
|
+
const defaultMsg = require_message.message`Unexpected option or subcommand: ${require_message.optionName(token)}.`;
|
|
274
|
+
if (options?.errors?.unexpectedInput != null) return typeof options.errors.unexpectedInput === "function" ? options.errors.unexpectedInput(token) : options.errors.unexpectedInput;
|
|
275
|
+
return createUnexpectedInputErrorWithScopedSuggestions(defaultMsg, token, parsers, options?.errors?.suggestions);
|
|
276
|
+
})()
|
|
231
277
|
});
|
|
232
278
|
const parseSync = (context) => {
|
|
233
279
|
let error = getInitialError(context);
|
|
@@ -423,7 +469,12 @@ function longestMatch(...args) {
|
|
|
423
469
|
const syncParsers = parsers;
|
|
424
470
|
const getInitialError = (context) => ({
|
|
425
471
|
consumed: 0,
|
|
426
|
-
error: context.buffer.length < 1 ? getNoMatchError(options, noMatchContext) :
|
|
472
|
+
error: context.buffer.length < 1 ? getNoMatchError(options, noMatchContext) : (() => {
|
|
473
|
+
const token = context.buffer[0];
|
|
474
|
+
const defaultMsg = require_message.message`Unexpected option or subcommand: ${require_message.optionName(token)}.`;
|
|
475
|
+
if (options?.errors?.unexpectedInput != null) return typeof options.errors.unexpectedInput === "function" ? options.errors.unexpectedInput(token) : options.errors.unexpectedInput;
|
|
476
|
+
return createUnexpectedInputErrorWithScopedSuggestions(defaultMsg, token, parsers, options?.errors?.suggestions);
|
|
477
|
+
})()
|
|
427
478
|
});
|
|
428
479
|
const parseSync = (context) => {
|
|
429
480
|
let bestMatch = null;
|
package/dist/constructs.js
CHANGED
|
@@ -1,11 +1,62 @@
|
|
|
1
|
-
import { message, optionName, values } from "./message.js";
|
|
1
|
+
import { message, optionName, text, values } from "./message.js";
|
|
2
2
|
import { DependencyRegistry, dependencyId, isDeferredParseState, isDependencySourceState, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, wrappedDependencySourceMarker } from "./dependency.js";
|
|
3
3
|
import { dispatchByMode, dispatchIterableByMode } from "./mode-dispatch.js";
|
|
4
4
|
import { extractArgumentMetavars, extractCommandNames, extractOptionNames } from "./usage.js";
|
|
5
|
-
import { createErrorWithSuggestions, deduplicateSuggestions } from "./suggestion.js";
|
|
5
|
+
import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, deduplicateSuggestions, findSimilar } from "./suggestion.js";
|
|
6
6
|
|
|
7
7
|
//#region src/constructs.ts
|
|
8
8
|
/**
|
|
9
|
+
* Collects option names and command names that are valid at the current
|
|
10
|
+
* parse position by walking the usage tree. Only "leading" candidates
|
|
11
|
+
* (those reachable before a required positional argument) are collected.
|
|
12
|
+
*/
|
|
13
|
+
function collectLeadingCandidates(terms, optionNames, commandNames) {
|
|
14
|
+
if (!terms || !Array.isArray(terms)) return true;
|
|
15
|
+
for (const term of terms) {
|
|
16
|
+
if (term.type === "option") {
|
|
17
|
+
for (const name of term.names) optionNames.add(name);
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (term.type === "command") {
|
|
21
|
+
commandNames.add(term.name);
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (term.type === "argument") return false;
|
|
25
|
+
if (term.type === "optional") {
|
|
26
|
+
collectLeadingCandidates(term.terms, optionNames, commandNames);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (term.type === "multiple") {
|
|
30
|
+
collectLeadingCandidates(term.terms, optionNames, commandNames);
|
|
31
|
+
if (term.min === 0) continue;
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (term.type === "exclusive") {
|
|
35
|
+
let allAlternativesSkippable = true;
|
|
36
|
+
for (const exclusiveUsage of term.terms) {
|
|
37
|
+
const alternativeSkippable = collectLeadingCandidates(exclusiveUsage, optionNames, commandNames);
|
|
38
|
+
allAlternativesSkippable = allAlternativesSkippable && alternativeSkippable;
|
|
39
|
+
}
|
|
40
|
+
if (allAlternativesSkippable) continue;
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
function createUnexpectedInputErrorWithScopedSuggestions(baseError, invalidInput, parsers, customFormatter) {
|
|
47
|
+
const options = /* @__PURE__ */ new Set();
|
|
48
|
+
const commands = /* @__PURE__ */ new Set();
|
|
49
|
+
for (const parser of parsers) collectLeadingCandidates(parser.usage, options, commands);
|
|
50
|
+
const candidates = new Set([...options, ...commands]);
|
|
51
|
+
const suggestions = findSimilar(invalidInput, candidates, DEFAULT_FIND_SIMILAR_OPTIONS);
|
|
52
|
+
const suggestionMsg = customFormatter ? customFormatter(suggestions) : createSuggestionMessage(suggestions);
|
|
53
|
+
return suggestionMsg.length > 0 ? [
|
|
54
|
+
...baseError,
|
|
55
|
+
text("\n\n"),
|
|
56
|
+
...suggestionMsg
|
|
57
|
+
] : baseError;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
9
60
|
* Checks if the given token is an option name that requires a value
|
|
10
61
|
* (i.e., has a metavar) within the given usage terms.
|
|
11
62
|
* @param usage The usage terms to search through.
|
|
@@ -200,16 +251,6 @@ function getNoMatchError(options, noMatchContext) {
|
|
|
200
251
|
return customNoMatch ? typeof customNoMatch === "function" ? customNoMatch(noMatchContext) : customNoMatch : generateNoMatchError(noMatchContext);
|
|
201
252
|
}
|
|
202
253
|
/**
|
|
203
|
-
* Creates default error for parse() method when buffer is not empty.
|
|
204
|
-
* Shared by or() and longestMatch().
|
|
205
|
-
* @internal
|
|
206
|
-
*/
|
|
207
|
-
function createUnexpectedInputError(token, usage, options) {
|
|
208
|
-
const defaultMsg = message`Unexpected option or subcommand: ${optionName(token)}.`;
|
|
209
|
-
if (options?.errors?.unexpectedInput != null) return typeof options.errors.unexpectedInput === "function" ? options.errors.unexpectedInput(token) : options.errors.unexpectedInput;
|
|
210
|
-
return createErrorWithSuggestions(defaultMsg, token, usage, "both", options?.errors?.suggestions);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
254
|
* @since 0.5.0
|
|
214
255
|
*/
|
|
215
256
|
function or(...args) {
|
|
@@ -227,7 +268,12 @@ function or(...args) {
|
|
|
227
268
|
const syncParsers = parsers;
|
|
228
269
|
const getInitialError = (context) => ({
|
|
229
270
|
consumed: 0,
|
|
230
|
-
error: context.buffer.length < 1 ? getNoMatchError(options, noMatchContext) :
|
|
271
|
+
error: context.buffer.length < 1 ? getNoMatchError(options, noMatchContext) : (() => {
|
|
272
|
+
const token = context.buffer[0];
|
|
273
|
+
const defaultMsg = message`Unexpected option or subcommand: ${optionName(token)}.`;
|
|
274
|
+
if (options?.errors?.unexpectedInput != null) return typeof options.errors.unexpectedInput === "function" ? options.errors.unexpectedInput(token) : options.errors.unexpectedInput;
|
|
275
|
+
return createUnexpectedInputErrorWithScopedSuggestions(defaultMsg, token, parsers, options?.errors?.suggestions);
|
|
276
|
+
})()
|
|
231
277
|
});
|
|
232
278
|
const parseSync = (context) => {
|
|
233
279
|
let error = getInitialError(context);
|
|
@@ -423,7 +469,12 @@ function longestMatch(...args) {
|
|
|
423
469
|
const syncParsers = parsers;
|
|
424
470
|
const getInitialError = (context) => ({
|
|
425
471
|
consumed: 0,
|
|
426
|
-
error: context.buffer.length < 1 ? getNoMatchError(options, noMatchContext) :
|
|
472
|
+
error: context.buffer.length < 1 ? getNoMatchError(options, noMatchContext) : (() => {
|
|
473
|
+
const token = context.buffer[0];
|
|
474
|
+
const defaultMsg = message`Unexpected option or subcommand: ${optionName(token)}.`;
|
|
475
|
+
if (options?.errors?.unexpectedInput != null) return typeof options.errors.unexpectedInput === "function" ? options.errors.unexpectedInput(token) : options.errors.unexpectedInput;
|
|
476
|
+
return createUnexpectedInputErrorWithScopedSuggestions(defaultMsg, token, parsers, options?.errors?.suggestions);
|
|
477
|
+
})()
|
|
427
478
|
});
|
|
428
479
|
const parseSync = (context) => {
|
|
429
480
|
let bestMatch = null;
|
package/dist/facade.cjs
CHANGED
|
@@ -55,7 +55,7 @@ function createVersionParser(mode) {
|
|
|
55
55
|
/**
|
|
56
56
|
* Creates completion parsers based on the specified mode.
|
|
57
57
|
*/
|
|
58
|
-
function createCompletionParser(mode, programName, availableShells, name = "both") {
|
|
58
|
+
function createCompletionParser(mode, programName, availableShells, name = "both", helpVisibility = name) {
|
|
59
59
|
const shellList = [];
|
|
60
60
|
for (const shell in availableShells) {
|
|
61
61
|
if (shellList.length > 0) shellList.push(require_message.text(", "));
|
|
@@ -78,18 +78,27 @@ function createCompletionParser(mode, programName, availableShells, name = "both
|
|
|
78
78
|
`
|
|
79
79
|
};
|
|
80
80
|
const completionCommands = [];
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
const showSingular = helpVisibility === "singular" || helpVisibility === "both";
|
|
82
|
+
const showPlural = helpVisibility === "plural" || helpVisibility === "both";
|
|
83
|
+
if (name === "singular" || name === "both") completionCommands.push(require_primitives.command("completion", completionInner, {
|
|
84
|
+
...completionCommandConfig,
|
|
85
|
+
hidden: !showSingular
|
|
86
|
+
}));
|
|
87
|
+
if (name === "plural" || name === "both") completionCommands.push(require_primitives.command("completions", completionInner, {
|
|
88
|
+
...completionCommandConfig,
|
|
89
|
+
hidden: !showPlural
|
|
90
|
+
}));
|
|
83
91
|
const completionCommand = require_constructs.longestMatch(...completionCommands);
|
|
84
|
-
const
|
|
85
|
-
if (name === "singular" || name === "both")
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
const completionOptions = [];
|
|
93
|
+
if (name === "singular" || name === "both") completionOptions.push(require_primitives.option("--completion", require_valueparser.string({ metavar: "SHELL" }), {
|
|
94
|
+
description: require_message.message`Generate shell completion script.`,
|
|
95
|
+
hidden: !showSingular
|
|
96
|
+
}));
|
|
97
|
+
if (name === "plural" || name === "both") completionOptions.push(require_primitives.option("--completions", require_valueparser.string({ metavar: "SHELL" }), {
|
|
98
|
+
description: require_message.message`Generate shell completion script.`,
|
|
99
|
+
hidden: !showPlural
|
|
100
|
+
}));
|
|
101
|
+
const completionOption = completionOptions.length === 1 ? completionOptions[0] : require_constructs.longestMatch(completionOptions[0], completionOptions[1]);
|
|
93
102
|
const argsParser = require_modifiers.withDefault(require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "ARG" }), { description: require_message.message`Command line arguments for completion suggestions (used by shell integration; you usually don't need to provide this).` })), []);
|
|
94
103
|
const optionParser = require_constructs.object({
|
|
95
104
|
shell: completionOption,
|
|
@@ -441,6 +450,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
441
450
|
const onVersion = options.version?.onShow ?? (() => ({}));
|
|
442
451
|
const completionMode = options.completion?.mode ?? "both";
|
|
443
452
|
const completionName = options.completion?.name ?? "both";
|
|
453
|
+
const completionHelpVisibility = options.completion?.helpVisibility ?? completionName;
|
|
444
454
|
const onCompletion = options.completion?.onShow ?? (() => ({}));
|
|
445
455
|
const defaultShells = {
|
|
446
456
|
bash: require_completion.bash,
|
|
@@ -467,7 +477,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
467
477
|
const completionParsers = completion === "none" ? {
|
|
468
478
|
completionCommand: null,
|
|
469
479
|
completionOption: null
|
|
470
|
-
} : createCompletionParser(completion, programName, availableShells, completionName);
|
|
480
|
+
} : createCompletionParser(completion, programName, availableShells, completionName, completionHelpVisibility);
|
|
471
481
|
if (options.completion) {
|
|
472
482
|
const hasHelpOption = args.includes("--help");
|
|
473
483
|
if ((completionMode === "command" || completionMode === "both") && args.length >= 1 && ((completionName === "singular" || completionName === "both" ? args[0] === "completion" : false) || (completionName === "plural" || completionName === "both" ? args[0] === "completions" : false)) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName);
|
|
@@ -482,9 +492,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
482
492
|
} else {
|
|
483
493
|
const singularMatchExact = completionName === "singular" || completionName === "both" ? arg === "--completion" : false;
|
|
484
494
|
const pluralMatchExact = completionName === "plural" || completionName === "both" ? arg === "--completions" : false;
|
|
485
|
-
if (
|
|
486
|
-
const shell = args[i + 1];
|
|
487
|
-
const completionArgs = args.slice(i + 2);
|
|
495
|
+
if (singularMatchExact || pluralMatchExact) {
|
|
496
|
+
const shell = i + 1 < args.length ? args[i + 1] : "";
|
|
497
|
+
const completionArgs = i + 1 < args.length ? args.slice(i + 2) : [];
|
|
488
498
|
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName);
|
|
489
499
|
}
|
|
490
500
|
}
|
package/dist/facade.d.cts
CHANGED
|
@@ -7,6 +7,81 @@ import { Program } from "./program.cjs";
|
|
|
7
7
|
|
|
8
8
|
//#region src/facade.d.ts
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Naming style for shell completion command and option aliases.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.10.0
|
|
14
|
+
*/
|
|
15
|
+
type CompletionName = "singular" | "plural" | "both";
|
|
16
|
+
/**
|
|
17
|
+
* Visibility policy for completion entries in help and usage output.
|
|
18
|
+
*
|
|
19
|
+
* @since 0.10.0
|
|
20
|
+
*/
|
|
21
|
+
type CompletionHelpVisibility = CompletionName | "none";
|
|
22
|
+
type CompletionConfigBase<THelp> = {
|
|
23
|
+
/**
|
|
24
|
+
* Determines how completion is made available:
|
|
25
|
+
*
|
|
26
|
+
* - `"command"`: Only the `completion` subcommand is available
|
|
27
|
+
* - `"option"`: Only the `--completion` option is available
|
|
28
|
+
* - `"both"`: Both `completion` subcommand and `--completion` option are available
|
|
29
|
+
*
|
|
30
|
+
* @default `"both"`
|
|
31
|
+
*/
|
|
32
|
+
readonly mode?: "command" | "option" | "both";
|
|
33
|
+
/**
|
|
34
|
+
* Available shell completions. By default, includes `bash`, `fish`, `nu`,
|
|
35
|
+
* `pwsh`, and `zsh`. You can provide additional custom shell completions or
|
|
36
|
+
* override the defaults.
|
|
37
|
+
*
|
|
38
|
+
* @default `{ bash, fish, nu, pwsh, zsh }`
|
|
39
|
+
*/
|
|
40
|
+
readonly shells?: Record<string, ShellCompletion>;
|
|
41
|
+
/**
|
|
42
|
+
* Callback function invoked when completion is requested. The function can
|
|
43
|
+
* optionally receive an exit code parameter.
|
|
44
|
+
*
|
|
45
|
+
* You usually want to pass `process.exit` on Node.js or Bun and `Deno.exit`
|
|
46
|
+
* on Deno to this option.
|
|
47
|
+
*
|
|
48
|
+
* @default Returns `void` when completion is shown.
|
|
49
|
+
*/
|
|
50
|
+
readonly onShow?: (() => THelp) | ((exitCode: number) => THelp);
|
|
51
|
+
};
|
|
52
|
+
type CompletionConfigBoth<THelp> = CompletionConfigBase<THelp> & {
|
|
53
|
+
/**
|
|
54
|
+
* Determines whether to use singular or plural naming for completion command/option.
|
|
55
|
+
*
|
|
56
|
+
* - `"singular"`: Use `completion` / `--completion`
|
|
57
|
+
* - `"plural"`: Use `completions` / `--completions`
|
|
58
|
+
* - `"both"`: Use both singular and plural forms
|
|
59
|
+
*
|
|
60
|
+
* @default `"both"`
|
|
61
|
+
*/
|
|
62
|
+
readonly name?: "both";
|
|
63
|
+
/**
|
|
64
|
+
* Controls which completion entries appear in help and usage output.
|
|
65
|
+
*
|
|
66
|
+
* - `"both"`: Show both singular and plural entries
|
|
67
|
+
* - `"singular"`: Show only singular entries
|
|
68
|
+
* - `"plural"`: Show only plural entries
|
|
69
|
+
* - `"none"`: Hide completion entries from help and usage
|
|
70
|
+
*
|
|
71
|
+
* @default Matches `name`
|
|
72
|
+
* @since 0.10.0
|
|
73
|
+
*/
|
|
74
|
+
readonly helpVisibility?: CompletionHelpVisibility;
|
|
75
|
+
};
|
|
76
|
+
type CompletionConfigSingular<THelp> = CompletionConfigBase<THelp> & {
|
|
77
|
+
readonly name: "singular";
|
|
78
|
+
readonly helpVisibility?: "singular" | "none";
|
|
79
|
+
};
|
|
80
|
+
type CompletionConfigPlural<THelp> = CompletionConfigBase<THelp> & {
|
|
81
|
+
readonly name: "plural";
|
|
82
|
+
readonly helpVisibility?: "plural" | "none";
|
|
83
|
+
};
|
|
84
|
+
type CompletionConfig<THelp> = CompletionConfigBoth<THelp> | CompletionConfigSingular<THelp> | CompletionConfigPlural<THelp>;
|
|
10
85
|
/**
|
|
11
86
|
* Configuration options for the {@link run} function.
|
|
12
87
|
*
|
|
@@ -95,46 +170,7 @@ interface RunOptions<THelp, TError> {
|
|
|
95
170
|
* Completion configuration. When provided, enables shell completion functionality.
|
|
96
171
|
* @since 0.6.0
|
|
97
172
|
*/
|
|
98
|
-
readonly completion?:
|
|
99
|
-
/**
|
|
100
|
-
* Determines how completion is made available:
|
|
101
|
-
*
|
|
102
|
-
* - `"command"`: Only the `completion` subcommand is available
|
|
103
|
-
* - `"option"`: Only the `--completion` option is available
|
|
104
|
-
* - `"both"`: Both `completion` subcommand and `--completion` option are available
|
|
105
|
-
*
|
|
106
|
-
* @default `"both"`
|
|
107
|
-
*/
|
|
108
|
-
readonly mode?: "command" | "option" | "both";
|
|
109
|
-
/**
|
|
110
|
-
* Determines whether to use singular or plural naming for completion command/option.
|
|
111
|
-
*
|
|
112
|
-
* - `"singular"`: Use `completion` / `--completion`
|
|
113
|
-
* - `"plural"`: Use `completions` / `--completions`
|
|
114
|
-
* - `"both"`: Use both singular and plural forms
|
|
115
|
-
*
|
|
116
|
-
* @default `"both"`
|
|
117
|
-
*/
|
|
118
|
-
readonly name?: "singular" | "plural" | "both";
|
|
119
|
-
/**
|
|
120
|
-
* Available shell completions. By default, includes `bash`, `fish`, `nu`,
|
|
121
|
-
* `pwsh`, and `zsh`. You can provide additional custom shell completions or
|
|
122
|
-
* override the defaults.
|
|
123
|
-
*
|
|
124
|
-
* @default `{ bash, fish, nu, pwsh, zsh }`
|
|
125
|
-
*/
|
|
126
|
-
readonly shells?: Record<string, ShellCompletion>;
|
|
127
|
-
/**
|
|
128
|
-
* Callback function invoked when completion is requested. The function can
|
|
129
|
-
* optionally receive an exit code parameter.
|
|
130
|
-
*
|
|
131
|
-
* You usually want to pass `process.exit` on Node.js or Bun and `Deno.exit`
|
|
132
|
-
* on Deno to this option.
|
|
133
|
-
*
|
|
134
|
-
* @default Returns `void` when completion is shown.
|
|
135
|
-
*/
|
|
136
|
-
readonly onShow?: (() => THelp) | ((exitCode: number) => THelp);
|
|
137
|
-
};
|
|
173
|
+
readonly completion?: CompletionConfig<THelp>;
|
|
138
174
|
/**
|
|
139
175
|
* What to display above error messages:
|
|
140
176
|
* - `"usage"`: Show usage information
|
|
@@ -412,4 +448,4 @@ declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, T
|
|
|
412
448
|
*/
|
|
413
449
|
declare function runWithAsync<TParser extends Parser<Mode, unknown, unknown>, TContexts extends readonly SourceContext<unknown>[], THelp = void, TError = never>(parser: TParser, programName: string, contexts: TContexts, options: RunWithOptions<THelp, TError> & ExtractRequiredOptions<TContexts, InferValue<TParser>>): Promise<InferValue<TParser>>;
|
|
414
450
|
//#endregion
|
|
415
|
-
export { ExtractRequiredOptions, type ParserValuePlaceholder, RunOptions, RunParserError, RunWithOptions, type SourceContext, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync };
|
|
451
|
+
export { CompletionHelpVisibility, CompletionName, ExtractRequiredOptions, type ParserValuePlaceholder, RunOptions, RunParserError, RunWithOptions, type SourceContext, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync };
|
package/dist/facade.d.ts
CHANGED
|
@@ -7,6 +7,81 @@ import { Program } from "./program.js";
|
|
|
7
7
|
|
|
8
8
|
//#region src/facade.d.ts
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Naming style for shell completion command and option aliases.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.10.0
|
|
14
|
+
*/
|
|
15
|
+
type CompletionName = "singular" | "plural" | "both";
|
|
16
|
+
/**
|
|
17
|
+
* Visibility policy for completion entries in help and usage output.
|
|
18
|
+
*
|
|
19
|
+
* @since 0.10.0
|
|
20
|
+
*/
|
|
21
|
+
type CompletionHelpVisibility = CompletionName | "none";
|
|
22
|
+
type CompletionConfigBase<THelp> = {
|
|
23
|
+
/**
|
|
24
|
+
* Determines how completion is made available:
|
|
25
|
+
*
|
|
26
|
+
* - `"command"`: Only the `completion` subcommand is available
|
|
27
|
+
* - `"option"`: Only the `--completion` option is available
|
|
28
|
+
* - `"both"`: Both `completion` subcommand and `--completion` option are available
|
|
29
|
+
*
|
|
30
|
+
* @default `"both"`
|
|
31
|
+
*/
|
|
32
|
+
readonly mode?: "command" | "option" | "both";
|
|
33
|
+
/**
|
|
34
|
+
* Available shell completions. By default, includes `bash`, `fish`, `nu`,
|
|
35
|
+
* `pwsh`, and `zsh`. You can provide additional custom shell completions or
|
|
36
|
+
* override the defaults.
|
|
37
|
+
*
|
|
38
|
+
* @default `{ bash, fish, nu, pwsh, zsh }`
|
|
39
|
+
*/
|
|
40
|
+
readonly shells?: Record<string, ShellCompletion>;
|
|
41
|
+
/**
|
|
42
|
+
* Callback function invoked when completion is requested. The function can
|
|
43
|
+
* optionally receive an exit code parameter.
|
|
44
|
+
*
|
|
45
|
+
* You usually want to pass `process.exit` on Node.js or Bun and `Deno.exit`
|
|
46
|
+
* on Deno to this option.
|
|
47
|
+
*
|
|
48
|
+
* @default Returns `void` when completion is shown.
|
|
49
|
+
*/
|
|
50
|
+
readonly onShow?: (() => THelp) | ((exitCode: number) => THelp);
|
|
51
|
+
};
|
|
52
|
+
type CompletionConfigBoth<THelp> = CompletionConfigBase<THelp> & {
|
|
53
|
+
/**
|
|
54
|
+
* Determines whether to use singular or plural naming for completion command/option.
|
|
55
|
+
*
|
|
56
|
+
* - `"singular"`: Use `completion` / `--completion`
|
|
57
|
+
* - `"plural"`: Use `completions` / `--completions`
|
|
58
|
+
* - `"both"`: Use both singular and plural forms
|
|
59
|
+
*
|
|
60
|
+
* @default `"both"`
|
|
61
|
+
*/
|
|
62
|
+
readonly name?: "both";
|
|
63
|
+
/**
|
|
64
|
+
* Controls which completion entries appear in help and usage output.
|
|
65
|
+
*
|
|
66
|
+
* - `"both"`: Show both singular and plural entries
|
|
67
|
+
* - `"singular"`: Show only singular entries
|
|
68
|
+
* - `"plural"`: Show only plural entries
|
|
69
|
+
* - `"none"`: Hide completion entries from help and usage
|
|
70
|
+
*
|
|
71
|
+
* @default Matches `name`
|
|
72
|
+
* @since 0.10.0
|
|
73
|
+
*/
|
|
74
|
+
readonly helpVisibility?: CompletionHelpVisibility;
|
|
75
|
+
};
|
|
76
|
+
type CompletionConfigSingular<THelp> = CompletionConfigBase<THelp> & {
|
|
77
|
+
readonly name: "singular";
|
|
78
|
+
readonly helpVisibility?: "singular" | "none";
|
|
79
|
+
};
|
|
80
|
+
type CompletionConfigPlural<THelp> = CompletionConfigBase<THelp> & {
|
|
81
|
+
readonly name: "plural";
|
|
82
|
+
readonly helpVisibility?: "plural" | "none";
|
|
83
|
+
};
|
|
84
|
+
type CompletionConfig<THelp> = CompletionConfigBoth<THelp> | CompletionConfigSingular<THelp> | CompletionConfigPlural<THelp>;
|
|
10
85
|
/**
|
|
11
86
|
* Configuration options for the {@link run} function.
|
|
12
87
|
*
|
|
@@ -95,46 +170,7 @@ interface RunOptions<THelp, TError> {
|
|
|
95
170
|
* Completion configuration. When provided, enables shell completion functionality.
|
|
96
171
|
* @since 0.6.0
|
|
97
172
|
*/
|
|
98
|
-
readonly completion?:
|
|
99
|
-
/**
|
|
100
|
-
* Determines how completion is made available:
|
|
101
|
-
*
|
|
102
|
-
* - `"command"`: Only the `completion` subcommand is available
|
|
103
|
-
* - `"option"`: Only the `--completion` option is available
|
|
104
|
-
* - `"both"`: Both `completion` subcommand and `--completion` option are available
|
|
105
|
-
*
|
|
106
|
-
* @default `"both"`
|
|
107
|
-
*/
|
|
108
|
-
readonly mode?: "command" | "option" | "both";
|
|
109
|
-
/**
|
|
110
|
-
* Determines whether to use singular or plural naming for completion command/option.
|
|
111
|
-
*
|
|
112
|
-
* - `"singular"`: Use `completion` / `--completion`
|
|
113
|
-
* - `"plural"`: Use `completions` / `--completions`
|
|
114
|
-
* - `"both"`: Use both singular and plural forms
|
|
115
|
-
*
|
|
116
|
-
* @default `"both"`
|
|
117
|
-
*/
|
|
118
|
-
readonly name?: "singular" | "plural" | "both";
|
|
119
|
-
/**
|
|
120
|
-
* Available shell completions. By default, includes `bash`, `fish`, `nu`,
|
|
121
|
-
* `pwsh`, and `zsh`. You can provide additional custom shell completions or
|
|
122
|
-
* override the defaults.
|
|
123
|
-
*
|
|
124
|
-
* @default `{ bash, fish, nu, pwsh, zsh }`
|
|
125
|
-
*/
|
|
126
|
-
readonly shells?: Record<string, ShellCompletion>;
|
|
127
|
-
/**
|
|
128
|
-
* Callback function invoked when completion is requested. The function can
|
|
129
|
-
* optionally receive an exit code parameter.
|
|
130
|
-
*
|
|
131
|
-
* You usually want to pass `process.exit` on Node.js or Bun and `Deno.exit`
|
|
132
|
-
* on Deno to this option.
|
|
133
|
-
*
|
|
134
|
-
* @default Returns `void` when completion is shown.
|
|
135
|
-
*/
|
|
136
|
-
readonly onShow?: (() => THelp) | ((exitCode: number) => THelp);
|
|
137
|
-
};
|
|
173
|
+
readonly completion?: CompletionConfig<THelp>;
|
|
138
174
|
/**
|
|
139
175
|
* What to display above error messages:
|
|
140
176
|
* - `"usage"`: Show usage information
|
|
@@ -412,4 +448,4 @@ declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, T
|
|
|
412
448
|
*/
|
|
413
449
|
declare function runWithAsync<TParser extends Parser<Mode, unknown, unknown>, TContexts extends readonly SourceContext<unknown>[], THelp = void, TError = never>(parser: TParser, programName: string, contexts: TContexts, options: RunWithOptions<THelp, TError> & ExtractRequiredOptions<TContexts, InferValue<TParser>>): Promise<InferValue<TParser>>;
|
|
414
450
|
//#endregion
|
|
415
|
-
export { ExtractRequiredOptions, type ParserValuePlaceholder, RunOptions, RunParserError, RunWithOptions, type SourceContext, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync };
|
|
451
|
+
export { CompletionHelpVisibility, CompletionName, ExtractRequiredOptions, type ParserValuePlaceholder, RunOptions, RunParserError, RunWithOptions, type SourceContext, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync };
|
package/dist/facade.js
CHANGED
|
@@ -55,7 +55,7 @@ function createVersionParser(mode) {
|
|
|
55
55
|
/**
|
|
56
56
|
* Creates completion parsers based on the specified mode.
|
|
57
57
|
*/
|
|
58
|
-
function createCompletionParser(mode, programName, availableShells, name = "both") {
|
|
58
|
+
function createCompletionParser(mode, programName, availableShells, name = "both", helpVisibility = name) {
|
|
59
59
|
const shellList = [];
|
|
60
60
|
for (const shell in availableShells) {
|
|
61
61
|
if (shellList.length > 0) shellList.push(text(", "));
|
|
@@ -78,18 +78,27 @@ function createCompletionParser(mode, programName, availableShells, name = "both
|
|
|
78
78
|
`
|
|
79
79
|
};
|
|
80
80
|
const completionCommands = [];
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
const showSingular = helpVisibility === "singular" || helpVisibility === "both";
|
|
82
|
+
const showPlural = helpVisibility === "plural" || helpVisibility === "both";
|
|
83
|
+
if (name === "singular" || name === "both") completionCommands.push(command("completion", completionInner, {
|
|
84
|
+
...completionCommandConfig,
|
|
85
|
+
hidden: !showSingular
|
|
86
|
+
}));
|
|
87
|
+
if (name === "plural" || name === "both") completionCommands.push(command("completions", completionInner, {
|
|
88
|
+
...completionCommandConfig,
|
|
89
|
+
hidden: !showPlural
|
|
90
|
+
}));
|
|
83
91
|
const completionCommand = longestMatch(...completionCommands);
|
|
84
|
-
const
|
|
85
|
-
if (name === "singular" || name === "both")
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
const completionOptions = [];
|
|
93
|
+
if (name === "singular" || name === "both") completionOptions.push(option("--completion", string({ metavar: "SHELL" }), {
|
|
94
|
+
description: message`Generate shell completion script.`,
|
|
95
|
+
hidden: !showSingular
|
|
96
|
+
}));
|
|
97
|
+
if (name === "plural" || name === "both") completionOptions.push(option("--completions", string({ metavar: "SHELL" }), {
|
|
98
|
+
description: message`Generate shell completion script.`,
|
|
99
|
+
hidden: !showPlural
|
|
100
|
+
}));
|
|
101
|
+
const completionOption = completionOptions.length === 1 ? completionOptions[0] : longestMatch(completionOptions[0], completionOptions[1]);
|
|
93
102
|
const argsParser = withDefault(multiple(argument(string({ metavar: "ARG" }), { description: message`Command line arguments for completion suggestions (used by shell integration; you usually don't need to provide this).` })), []);
|
|
94
103
|
const optionParser = object({
|
|
95
104
|
shell: completionOption,
|
|
@@ -441,6 +450,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
441
450
|
const onVersion = options.version?.onShow ?? (() => ({}));
|
|
442
451
|
const completionMode = options.completion?.mode ?? "both";
|
|
443
452
|
const completionName = options.completion?.name ?? "both";
|
|
453
|
+
const completionHelpVisibility = options.completion?.helpVisibility ?? completionName;
|
|
444
454
|
const onCompletion = options.completion?.onShow ?? (() => ({}));
|
|
445
455
|
const defaultShells = {
|
|
446
456
|
bash,
|
|
@@ -467,7 +477,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
467
477
|
const completionParsers = completion === "none" ? {
|
|
468
478
|
completionCommand: null,
|
|
469
479
|
completionOption: null
|
|
470
|
-
} : createCompletionParser(completion, programName, availableShells, completionName);
|
|
480
|
+
} : createCompletionParser(completion, programName, availableShells, completionName, completionHelpVisibility);
|
|
471
481
|
if (options.completion) {
|
|
472
482
|
const hasHelpOption = args.includes("--help");
|
|
473
483
|
if ((completionMode === "command" || completionMode === "both") && args.length >= 1 && ((completionName === "singular" || completionName === "both" ? args[0] === "completion" : false) || (completionName === "plural" || completionName === "both" ? args[0] === "completions" : false)) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName);
|
|
@@ -482,9 +492,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
482
492
|
} else {
|
|
483
493
|
const singularMatchExact = completionName === "singular" || completionName === "both" ? arg === "--completion" : false;
|
|
484
494
|
const pluralMatchExact = completionName === "plural" || completionName === "both" ? arg === "--completions" : false;
|
|
485
|
-
if (
|
|
486
|
-
const shell = args[i + 1];
|
|
487
|
-
const completionArgs = args.slice(i + 2);
|
|
495
|
+
if (singularMatchExact || pluralMatchExact) {
|
|
496
|
+
const shell = i + 1 < args.length ? args[i + 1] : "";
|
|
497
|
+
const completionArgs = i + 1 < args.length ? args.slice(i + 2) : [];
|
|
488
498
|
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName);
|
|
489
499
|
}
|
|
490
500
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -11,5 +11,5 @@ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOpti
|
|
|
11
11
|
import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.cjs";
|
|
12
12
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
|
|
13
13
|
import { ParserValuePlaceholder, SourceContext } from "./context.cjs";
|
|
14
|
-
import { ExtractRequiredOptions, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.cjs";
|
|
15
|
-
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, link, locale, longestMatch, macAddress, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
14
|
+
import { CompletionHelpVisibility, CompletionName, ExtractRequiredOptions, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.cjs";
|
|
15
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CompletionHelpVisibility, CompletionName, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, link, locale, longestMatch, macAddress, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,5 +11,5 @@ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOpti
|
|
|
11
11
|
import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
|
|
12
12
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
13
13
|
import { ParserValuePlaceholder, SourceContext } from "./context.js";
|
|
14
|
-
import { ExtractRequiredOptions, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
|
|
15
|
-
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, link, locale, longestMatch, macAddress, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
14
|
+
import { CompletionHelpVisibility, CompletionName, ExtractRequiredOptions, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
|
|
15
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CompletionHelpVisibility, CompletionName, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, link, locale, longestMatch, macAddress, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
package/dist/suggestion.cjs
CHANGED
|
@@ -232,5 +232,6 @@ function deduplicateSuggestions(suggestions) {
|
|
|
232
232
|
//#endregion
|
|
233
233
|
exports.DEFAULT_FIND_SIMILAR_OPTIONS = DEFAULT_FIND_SIMILAR_OPTIONS;
|
|
234
234
|
exports.createErrorWithSuggestions = createErrorWithSuggestions;
|
|
235
|
+
exports.createSuggestionMessage = createSuggestionMessage;
|
|
235
236
|
exports.deduplicateSuggestions = deduplicateSuggestions;
|
|
236
237
|
exports.findSimilar = findSimilar;
|
package/dist/suggestion.js
CHANGED
|
@@ -230,4 +230,4 @@ function deduplicateSuggestions(suggestions) {
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
//#endregion
|
|
233
|
-
export { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, deduplicateSuggestions, findSimilar };
|
|
233
|
+
export { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, deduplicateSuggestions, findSimilar };
|