@optique/core 0.6.0-dev.102 → 0.6.0-dev.103
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/facade.cjs +14 -10
- package/dist/facade.d.cts +9 -0
- package/dist/facade.d.ts +9 -0
- package/dist/facade.js +14 -10
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/facade.cjs
CHANGED
|
@@ -264,7 +264,7 @@ function classifyResult(result, args) {
|
|
|
264
264
|
* Handles shell completion requests.
|
|
265
265
|
* @since 0.6.0
|
|
266
266
|
*/
|
|
267
|
-
function handleCompletion(completionArgs, programName, parser, stdout, stderr, onCompletion, onError, colors) {
|
|
267
|
+
function handleCompletion(completionArgs, programName, parser, stdout, stderr, onCompletion, onError, availableShells, colors) {
|
|
268
268
|
if (completionArgs.length === 0) {
|
|
269
269
|
stderr("Error: Missing shell name for completion.\n");
|
|
270
270
|
stderr("Usage: " + programName + " completion <shell> [args...]\n");
|
|
@@ -272,12 +272,6 @@ function handleCompletion(completionArgs, programName, parser, stdout, stderr, o
|
|
|
272
272
|
}
|
|
273
273
|
const shellName = completionArgs[0];
|
|
274
274
|
const args = completionArgs.slice(1);
|
|
275
|
-
const availableShells = {
|
|
276
|
-
bash: require_completion.bash,
|
|
277
|
-
fish: require_completion.fish,
|
|
278
|
-
pwsh: require_completion.pwsh,
|
|
279
|
-
zsh: require_completion.zsh
|
|
280
|
-
};
|
|
281
275
|
const shell = availableShells[shellName];
|
|
282
276
|
if (!shell) {
|
|
283
277
|
const available = [];
|
|
@@ -340,17 +334,27 @@ function run(parser, programName, args, options = {}) {
|
|
|
340
334
|
const completionMode = options.completion?.mode ?? "both";
|
|
341
335
|
const onCompletion = options.completion?.onShow ?? (() => ({}));
|
|
342
336
|
if (options.completion) {
|
|
343
|
-
|
|
337
|
+
const defaultShells = {
|
|
338
|
+
bash: require_completion.bash,
|
|
339
|
+
fish: require_completion.fish,
|
|
340
|
+
pwsh: require_completion.pwsh,
|
|
341
|
+
zsh: require_completion.zsh
|
|
342
|
+
};
|
|
343
|
+
const availableShells = options.completion.shells ? {
|
|
344
|
+
...defaultShells,
|
|
345
|
+
...options.completion.shells
|
|
346
|
+
} : defaultShells;
|
|
347
|
+
if ((completionMode === "command" || completionMode === "both") && args.length >= 1 && args[0] === "completion") return handleCompletion(args.slice(1), programName, parser, stdout, stderr, onCompletion, onError, availableShells, colors);
|
|
344
348
|
if (completionMode === "option" || completionMode === "both") for (let i = 0; i < args.length; i++) {
|
|
345
349
|
const arg = args[i];
|
|
346
350
|
if (arg.startsWith("--completion=")) {
|
|
347
351
|
const shell = arg.slice(13);
|
|
348
352
|
const completionArgs = args.slice(i + 1);
|
|
349
|
-
return handleCompletion([shell, ...completionArgs], programName, parser, stdout, stderr, onCompletion, onError, colors);
|
|
353
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, stdout, stderr, onCompletion, onError, availableShells, colors);
|
|
350
354
|
} else if (arg === "--completion" && i + 1 < args.length) {
|
|
351
355
|
const shell = args[i + 1];
|
|
352
356
|
const completionArgs = args.slice(i + 2);
|
|
353
|
-
return handleCompletion([shell, ...completionArgs], programName, parser, stdout, stderr, onCompletion, onError, colors);
|
|
357
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, stdout, stderr, onCompletion, onError, availableShells, colors);
|
|
354
358
|
}
|
|
355
359
|
}
|
|
356
360
|
}
|
package/dist/facade.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Message } from "./message.cjs";
|
|
2
2
|
import { ShowDefaultOptions } from "./doc.cjs";
|
|
3
3
|
import { InferValue, Parser } from "./parser.cjs";
|
|
4
|
+
import { ShellCompletion } from "./completion.cjs";
|
|
4
5
|
|
|
5
6
|
//#region src/facade.d.ts
|
|
6
7
|
|
|
@@ -103,6 +104,14 @@ interface RunOptions<THelp, TError> {
|
|
|
103
104
|
* @default `"both"`
|
|
104
105
|
*/
|
|
105
106
|
readonly mode?: "command" | "option" | "both";
|
|
107
|
+
/**
|
|
108
|
+
* Available shell completions. By default, includes `bash`, `fish`, `pwsh`,
|
|
109
|
+
* and `zsh`. You can provide additional custom shell completions or override
|
|
110
|
+
* the defaults.
|
|
111
|
+
*
|
|
112
|
+
* @default `{ bash, fish, pwsh, zsh }`
|
|
113
|
+
*/
|
|
114
|
+
readonly shells?: Record<string, ShellCompletion>;
|
|
106
115
|
/**
|
|
107
116
|
* Callback function invoked when completion is requested. The function can
|
|
108
117
|
* optionally receive an exit code parameter.
|
package/dist/facade.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Message } from "./message.js";
|
|
2
2
|
import { ShowDefaultOptions } from "./doc.js";
|
|
3
3
|
import { InferValue, Parser } from "./parser.js";
|
|
4
|
+
import { ShellCompletion } from "./completion.js";
|
|
4
5
|
|
|
5
6
|
//#region src/facade.d.ts
|
|
6
7
|
|
|
@@ -103,6 +104,14 @@ interface RunOptions<THelp, TError> {
|
|
|
103
104
|
* @default `"both"`
|
|
104
105
|
*/
|
|
105
106
|
readonly mode?: "command" | "option" | "both";
|
|
107
|
+
/**
|
|
108
|
+
* Available shell completions. By default, includes `bash`, `fish`, `pwsh`,
|
|
109
|
+
* and `zsh`. You can provide additional custom shell completions or override
|
|
110
|
+
* the defaults.
|
|
111
|
+
*
|
|
112
|
+
* @default `{ bash, fish, pwsh, zsh }`
|
|
113
|
+
*/
|
|
114
|
+
readonly shells?: Record<string, ShellCompletion>;
|
|
106
115
|
/**
|
|
107
116
|
* Callback function invoked when completion is requested. The function can
|
|
108
117
|
* optionally receive an exit code parameter.
|
package/dist/facade.js
CHANGED
|
@@ -264,7 +264,7 @@ function classifyResult(result, args) {
|
|
|
264
264
|
* Handles shell completion requests.
|
|
265
265
|
* @since 0.6.0
|
|
266
266
|
*/
|
|
267
|
-
function handleCompletion(completionArgs, programName, parser, stdout, stderr, onCompletion, onError, colors) {
|
|
267
|
+
function handleCompletion(completionArgs, programName, parser, stdout, stderr, onCompletion, onError, availableShells, colors) {
|
|
268
268
|
if (completionArgs.length === 0) {
|
|
269
269
|
stderr("Error: Missing shell name for completion.\n");
|
|
270
270
|
stderr("Usage: " + programName + " completion <shell> [args...]\n");
|
|
@@ -272,12 +272,6 @@ function handleCompletion(completionArgs, programName, parser, stdout, stderr, o
|
|
|
272
272
|
}
|
|
273
273
|
const shellName = completionArgs[0];
|
|
274
274
|
const args = completionArgs.slice(1);
|
|
275
|
-
const availableShells = {
|
|
276
|
-
bash,
|
|
277
|
-
fish,
|
|
278
|
-
pwsh,
|
|
279
|
-
zsh
|
|
280
|
-
};
|
|
281
275
|
const shell = availableShells[shellName];
|
|
282
276
|
if (!shell) {
|
|
283
277
|
const available = [];
|
|
@@ -340,17 +334,27 @@ function run(parser, programName, args, options = {}) {
|
|
|
340
334
|
const completionMode = options.completion?.mode ?? "both";
|
|
341
335
|
const onCompletion = options.completion?.onShow ?? (() => ({}));
|
|
342
336
|
if (options.completion) {
|
|
343
|
-
|
|
337
|
+
const defaultShells = {
|
|
338
|
+
bash,
|
|
339
|
+
fish,
|
|
340
|
+
pwsh,
|
|
341
|
+
zsh
|
|
342
|
+
};
|
|
343
|
+
const availableShells = options.completion.shells ? {
|
|
344
|
+
...defaultShells,
|
|
345
|
+
...options.completion.shells
|
|
346
|
+
} : defaultShells;
|
|
347
|
+
if ((completionMode === "command" || completionMode === "both") && args.length >= 1 && args[0] === "completion") return handleCompletion(args.slice(1), programName, parser, stdout, stderr, onCompletion, onError, availableShells, colors);
|
|
344
348
|
if (completionMode === "option" || completionMode === "both") for (let i = 0; i < args.length; i++) {
|
|
345
349
|
const arg = args[i];
|
|
346
350
|
if (arg.startsWith("--completion=")) {
|
|
347
351
|
const shell = arg.slice(13);
|
|
348
352
|
const completionArgs = args.slice(i + 1);
|
|
349
|
-
return handleCompletion([shell, ...completionArgs], programName, parser, stdout, stderr, onCompletion, onError, colors);
|
|
353
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, stdout, stderr, onCompletion, onError, availableShells, colors);
|
|
350
354
|
} else if (arg === "--completion" && i + 1 < args.length) {
|
|
351
355
|
const shell = args[i + 1];
|
|
352
356
|
const completionArgs = args.slice(i + 2);
|
|
353
|
-
return handleCompletion([shell, ...completionArgs], programName, parser, stdout, stderr, onCompletion, onError, colors);
|
|
357
|
+
return handleCompletion([shell, ...completionArgs], programName, parser, stdout, stderr, onCompletion, onError, availableShells, colors);
|
|
354
358
|
}
|
|
355
359
|
}
|
|
356
360
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -6,6 +6,6 @@ import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOpt
|
|
|
6
6
|
import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, argument, command, constant, flag, option } from "./primitives.cjs";
|
|
7
7
|
import { DocState, InferValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, parse, suggest } from "./parser.cjs";
|
|
8
8
|
import { LongestMatchErrorOptions, LongestMatchOptions, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, concat, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
|
|
9
|
-
import { RunError, RunOptions, run } from "./facade.cjs";
|
|
10
9
|
import { ShellCompletion, bash, fish, pwsh, zsh } from "./completion.cjs";
|
|
10
|
+
import { RunError, RunOptions, run } from "./facade.cjs";
|
|
11
11
|
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, CommandErrorOptions, CommandOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, FlagErrorOptions, FlagOptions, FloatOptions, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, Message, MessageFormatOptions, MessageTerm, MultipleErrorOptions, MultipleOptions, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, Result, RunError, RunOptions, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, concat, constant, envVar, fish, 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, pwsh, run, string, suggest, text, tuple, url, uuid, value, values, withDefault, zsh };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOpt
|
|
|
6
6
|
import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, argument, command, constant, flag, option } from "./primitives.js";
|
|
7
7
|
import { DocState, InferValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, parse, suggest } from "./parser.js";
|
|
8
8
|
import { LongestMatchErrorOptions, LongestMatchOptions, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, concat, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
9
|
-
import { RunError, RunOptions, run } from "./facade.js";
|
|
10
9
|
import { ShellCompletion, bash, fish, pwsh, zsh } from "./completion.js";
|
|
10
|
+
import { RunError, RunOptions, run } from "./facade.js";
|
|
11
11
|
export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, CommandErrorOptions, CommandOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, FlagErrorOptions, FlagOptions, FloatOptions, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, Message, MessageFormatOptions, MessageTerm, MultipleErrorOptions, MultipleOptions, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, Result, RunError, RunOptions, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, concat, constant, envVar, fish, 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, pwsh, run, string, suggest, text, tuple, url, uuid, value, values, withDefault, zsh };
|