@optique/core 0.10.0-dev.363 → 0.10.0-dev.368
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 +3 -3
- package/dist/facade.js +3 -3
- 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/message.cjs +18 -1
- package/dist/message.d.cts +20 -1
- package/dist/message.d.ts +20 -1
- package/dist/message.js +18 -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
|
@@ -492,9 +492,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
492
492
|
} else {
|
|
493
493
|
const singularMatchExact = completionName === "singular" || completionName === "both" ? arg === "--completion" : false;
|
|
494
494
|
const pluralMatchExact = completionName === "plural" || completionName === "both" ? arg === "--completions" : false;
|
|
495
|
-
if (
|
|
496
|
-
const shell = args[i + 1];
|
|
497
|
-
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) : [];
|
|
498
498
|
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName);
|
|
499
499
|
}
|
|
500
500
|
}
|
package/dist/facade.js
CHANGED
|
@@ -492,9 +492,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
492
492
|
} else {
|
|
493
493
|
const singularMatchExact = completionName === "singular" || completionName === "both" ? arg === "--completion" : false;
|
|
494
494
|
const pluralMatchExact = completionName === "plural" || completionName === "both" ? arg === "--completions" : false;
|
|
495
|
-
if (
|
|
496
|
-
const shell = args[i + 1];
|
|
497
|
-
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) : [];
|
|
498
498
|
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName);
|
|
499
499
|
}
|
|
500
500
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -75,6 +75,7 @@ exports.isNonEmptyString = require_nonempty.isNonEmptyString;
|
|
|
75
75
|
exports.isPendingDependencySourceState = require_dependency.isPendingDependencySourceState;
|
|
76
76
|
exports.isValueParser = require_valueparser.isValueParser;
|
|
77
77
|
exports.isWrappedDependencySource = require_dependency.isWrappedDependencySource;
|
|
78
|
+
exports.lineBreak = require_message.lineBreak;
|
|
78
79
|
exports.link = require_message.link;
|
|
79
80
|
exports.locale = require_valueparser.locale;
|
|
80
81
|
exports.longestMatch = require_constructs.longestMatch;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Annotations, ParseOptions, annotationKey, getAnnotations } from "./annotations.cjs";
|
|
2
2
|
import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.cjs";
|
|
3
|
-
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.cjs";
|
|
3
|
+
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.cjs";
|
|
4
4
|
import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.cjs";
|
|
5
5
|
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage } from "./doc.cjs";
|
|
6
6
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.cjs";
|
|
@@ -12,4 +12,4 @@ import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, Mode
|
|
|
12
12
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
|
|
13
13
|
import { ParserValuePlaceholder, SourceContext } from "./context.cjs";
|
|
14
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 };
|
|
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, lineBreak, 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Annotations, ParseOptions, annotationKey, getAnnotations } from "./annotations.js";
|
|
2
2
|
import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
|
|
3
|
-
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
3
|
+
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
4
4
|
import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
|
|
5
5
|
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage } from "./doc.js";
|
|
6
6
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.js";
|
|
@@ -12,4 +12,4 @@ import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, Mode
|
|
|
12
12
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
13
13
|
import { ParserValuePlaceholder, SourceContext } from "./context.js";
|
|
14
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 };
|
|
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, lineBreak, 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.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { annotationKey, getAnnotations } from "./annotations.js";
|
|
2
|
-
import { commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
2
|
+
import { commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
3
3
|
import { bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
4
4
|
import { DependencyRegistry, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.js";
|
|
5
5
|
import { extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
|
|
@@ -12,4 +12,4 @@ import { argument, command, constant, flag, option, passThrough } from "./primit
|
|
|
12
12
|
import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
|
|
13
13
|
import { RunParserError, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
|
|
14
14
|
|
|
15
|
-
export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, 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 };
|
|
15
|
+
export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, 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, lineBreak, 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/message.cjs
CHANGED
|
@@ -140,6 +140,18 @@ function commandLine(commandLine$1) {
|
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
|
+
* Creates a {@link MessageTerm} for an explicit single-line break.
|
|
144
|
+
*
|
|
145
|
+
* Unlike single `\n` in `text()` terms (which are treated as soft breaks and
|
|
146
|
+
* normalized to spaces), this term always renders as a hard line break.
|
|
147
|
+
*
|
|
148
|
+
* @returns A {@link MessageTerm} representing an explicit line break.
|
|
149
|
+
* @since 0.10.0
|
|
150
|
+
*/
|
|
151
|
+
function lineBreak() {
|
|
152
|
+
return { type: "lineBreak" };
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
143
155
|
* Creates a {@link MessageTerm} for a URL.
|
|
144
156
|
* @param url The URL, which can be a URL object or a string that can be parsed
|
|
145
157
|
* as a URL. For example, `"https://example.com"` or
|
|
@@ -332,7 +344,11 @@ function formatMessage(msg, options = {}) {
|
|
|
332
344
|
text: useColors ? `\x1b[36m${cmd}${resetSequence}` : cmd,
|
|
333
345
|
width: cmd.length
|
|
334
346
|
};
|
|
335
|
-
} else if (term.type === "
|
|
347
|
+
} else if (term.type === "lineBreak") yield {
|
|
348
|
+
text: "\n",
|
|
349
|
+
width: -1
|
|
350
|
+
};
|
|
351
|
+
else if (term.type === "url") {
|
|
336
352
|
const urlString = term.url.href;
|
|
337
353
|
const displayText = useQuotes ? `<${urlString}>` : urlString;
|
|
338
354
|
if (useColors) {
|
|
@@ -369,6 +385,7 @@ function formatMessage(msg, options = {}) {
|
|
|
369
385
|
exports.commandLine = commandLine;
|
|
370
386
|
exports.envVar = envVar;
|
|
371
387
|
exports.formatMessage = formatMessage;
|
|
388
|
+
exports.lineBreak = lineBreak;
|
|
372
389
|
exports.link = link;
|
|
373
390
|
exports.message = message;
|
|
374
391
|
exports.metavar = metavar;
|
package/dist/message.d.cts
CHANGED
|
@@ -123,6 +123,15 @@ type MessageTerm =
|
|
|
123
123
|
*/
|
|
124
124
|
readonly commandLine: string;
|
|
125
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* An explicit single-line break term in the message.
|
|
128
|
+
* @since 0.10.0
|
|
129
|
+
*/ | {
|
|
130
|
+
/**
|
|
131
|
+
* The type of the term, which is `"lineBreak"` for an explicit line break.
|
|
132
|
+
*/
|
|
133
|
+
readonly type: "lineBreak";
|
|
134
|
+
}
|
|
126
135
|
/**
|
|
127
136
|
* A URL term in the message, which represents a clickable hyperlink.
|
|
128
137
|
* @since 0.10.0
|
|
@@ -223,6 +232,16 @@ declare function envVar(envVar: string): MessageTerm;
|
|
|
223
232
|
* @since 0.6.0
|
|
224
233
|
*/
|
|
225
234
|
declare function commandLine(commandLine: string): MessageTerm;
|
|
235
|
+
/**
|
|
236
|
+
* Creates a {@link MessageTerm} for an explicit single-line break.
|
|
237
|
+
*
|
|
238
|
+
* Unlike single `\n` in `text()` terms (which are treated as soft breaks and
|
|
239
|
+
* normalized to spaces), this term always renders as a hard line break.
|
|
240
|
+
*
|
|
241
|
+
* @returns A {@link MessageTerm} representing an explicit line break.
|
|
242
|
+
* @since 0.10.0
|
|
243
|
+
*/
|
|
244
|
+
declare function lineBreak(): MessageTerm;
|
|
226
245
|
/**
|
|
227
246
|
* Creates a {@link MessageTerm} for a URL.
|
|
228
247
|
* @param url The URL, which can be a URL object or a string that can be parsed
|
|
@@ -361,4 +380,4 @@ interface MessageFormatOptions {
|
|
|
361
380
|
*/
|
|
362
381
|
declare function formatMessage(msg: Message, options?: MessageFormatOptions): string;
|
|
363
382
|
//#endregion
|
|
364
|
-
export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
|
383
|
+
export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
package/dist/message.d.ts
CHANGED
|
@@ -123,6 +123,15 @@ type MessageTerm =
|
|
|
123
123
|
*/
|
|
124
124
|
readonly commandLine: string;
|
|
125
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* An explicit single-line break term in the message.
|
|
128
|
+
* @since 0.10.0
|
|
129
|
+
*/ | {
|
|
130
|
+
/**
|
|
131
|
+
* The type of the term, which is `"lineBreak"` for an explicit line break.
|
|
132
|
+
*/
|
|
133
|
+
readonly type: "lineBreak";
|
|
134
|
+
}
|
|
126
135
|
/**
|
|
127
136
|
* A URL term in the message, which represents a clickable hyperlink.
|
|
128
137
|
* @since 0.10.0
|
|
@@ -223,6 +232,16 @@ declare function envVar(envVar: string): MessageTerm;
|
|
|
223
232
|
* @since 0.6.0
|
|
224
233
|
*/
|
|
225
234
|
declare function commandLine(commandLine: string): MessageTerm;
|
|
235
|
+
/**
|
|
236
|
+
* Creates a {@link MessageTerm} for an explicit single-line break.
|
|
237
|
+
*
|
|
238
|
+
* Unlike single `\n` in `text()` terms (which are treated as soft breaks and
|
|
239
|
+
* normalized to spaces), this term always renders as a hard line break.
|
|
240
|
+
*
|
|
241
|
+
* @returns A {@link MessageTerm} representing an explicit line break.
|
|
242
|
+
* @since 0.10.0
|
|
243
|
+
*/
|
|
244
|
+
declare function lineBreak(): MessageTerm;
|
|
226
245
|
/**
|
|
227
246
|
* Creates a {@link MessageTerm} for a URL.
|
|
228
247
|
* @param url The URL, which can be a URL object or a string that can be parsed
|
|
@@ -361,4 +380,4 @@ interface MessageFormatOptions {
|
|
|
361
380
|
*/
|
|
362
381
|
declare function formatMessage(msg: Message, options?: MessageFormatOptions): string;
|
|
363
382
|
//#endregion
|
|
364
|
-
export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
|
383
|
+
export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
package/dist/message.js
CHANGED
|
@@ -139,6 +139,18 @@ function commandLine(commandLine$1) {
|
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
|
+
* Creates a {@link MessageTerm} for an explicit single-line break.
|
|
143
|
+
*
|
|
144
|
+
* Unlike single `\n` in `text()` terms (which are treated as soft breaks and
|
|
145
|
+
* normalized to spaces), this term always renders as a hard line break.
|
|
146
|
+
*
|
|
147
|
+
* @returns A {@link MessageTerm} representing an explicit line break.
|
|
148
|
+
* @since 0.10.0
|
|
149
|
+
*/
|
|
150
|
+
function lineBreak() {
|
|
151
|
+
return { type: "lineBreak" };
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
142
154
|
* Creates a {@link MessageTerm} for a URL.
|
|
143
155
|
* @param url The URL, which can be a URL object or a string that can be parsed
|
|
144
156
|
* as a URL. For example, `"https://example.com"` or
|
|
@@ -331,7 +343,11 @@ function formatMessage(msg, options = {}) {
|
|
|
331
343
|
text: useColors ? `\x1b[36m${cmd}${resetSequence}` : cmd,
|
|
332
344
|
width: cmd.length
|
|
333
345
|
};
|
|
334
|
-
} else if (term.type === "
|
|
346
|
+
} else if (term.type === "lineBreak") yield {
|
|
347
|
+
text: "\n",
|
|
348
|
+
width: -1
|
|
349
|
+
};
|
|
350
|
+
else if (term.type === "url") {
|
|
335
351
|
const urlString = term.url.href;
|
|
336
352
|
const displayText = useQuotes ? `<${urlString}>` : urlString;
|
|
337
353
|
if (useColors) {
|
|
@@ -365,4 +381,4 @@ function formatMessage(msg, options = {}) {
|
|
|
365
381
|
}
|
|
366
382
|
|
|
367
383
|
//#endregion
|
|
368
|
-
export { commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
|
384
|
+
export { commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
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 };
|