@optique/core 0.10.0-dev.327 → 0.10.0-dev.329
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/doc.cjs +42 -2
- package/dist/doc.d.cts +15 -0
- package/dist/doc.d.ts +15 -0
- package/dist/doc.js +42 -2
- package/dist/facade.cjs +10 -1
- package/dist/facade.d.cts +19 -1
- package/dist/facade.d.ts +19 -1
- package/dist/facade.js +10 -1
- 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 +52 -0
- package/dist/message.d.cts +39 -1
- package/dist/message.d.ts +39 -1
- package/dist/message.js +51 -1
- package/dist/program.d.cts +1 -1
- package/dist/program.d.ts +1 -1
- package/package.json +1 -1
package/dist/doc.cjs
CHANGED
|
@@ -46,7 +46,8 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
46
46
|
output += "\n";
|
|
47
47
|
}
|
|
48
48
|
if (page.usage != null) {
|
|
49
|
-
|
|
49
|
+
const usageLabel = options.colors ? "\x1B[1;2mUsage:\x1B[0m " : "Usage: ";
|
|
50
|
+
output += usageLabel;
|
|
50
51
|
output += indentLines(require_usage.formatUsage(programName, page.usage, {
|
|
51
52
|
colors: options.colors,
|
|
52
53
|
maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - 7,
|
|
@@ -67,7 +68,10 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
67
68
|
for (const section of sections) {
|
|
68
69
|
if (section.entries.length < 1) continue;
|
|
69
70
|
output += "\n";
|
|
70
|
-
if (section.title != null)
|
|
71
|
+
if (section.title != null) {
|
|
72
|
+
const sectionLabel = options.colors ? `\x1b[1;2m${section.title}:\x1b[0m\n` : `${section.title}:\n`;
|
|
73
|
+
output += sectionLabel;
|
|
74
|
+
}
|
|
71
75
|
for (const entry of section.entries) {
|
|
72
76
|
const term = require_usage.formatUsageTerm(entry.term, {
|
|
73
77
|
colors: options.colors,
|
|
@@ -92,6 +96,42 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
92
96
|
output += `${" ".repeat(termIndent)}${ansiAwareRightPad(term, termWidth)} ${description === "" ? "" : indentLines(description, termIndent + termWidth + 2)}\n`;
|
|
93
97
|
}
|
|
94
98
|
}
|
|
99
|
+
if (page.examples != null) {
|
|
100
|
+
output += "\n";
|
|
101
|
+
const examplesLabel = options.colors ? "\x1B[1;2mExamples:\x1B[0m\n" : "Examples:\n";
|
|
102
|
+
output += examplesLabel;
|
|
103
|
+
const examplesContent = require_message.formatMessage(page.examples, {
|
|
104
|
+
colors: options.colors,
|
|
105
|
+
maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - 2,
|
|
106
|
+
quotes: !options.colors
|
|
107
|
+
});
|
|
108
|
+
output += " " + indentLines(examplesContent, 2);
|
|
109
|
+
output += "\n";
|
|
110
|
+
}
|
|
111
|
+
if (page.author != null) {
|
|
112
|
+
output += "\n";
|
|
113
|
+
const authorLabel = options.colors ? "\x1B[1;2mAuthor:\x1B[0m\n" : "Author:\n";
|
|
114
|
+
output += authorLabel;
|
|
115
|
+
const authorContent = require_message.formatMessage(page.author, {
|
|
116
|
+
colors: options.colors,
|
|
117
|
+
maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - 2,
|
|
118
|
+
quotes: !options.colors
|
|
119
|
+
});
|
|
120
|
+
output += " " + indentLines(authorContent, 2);
|
|
121
|
+
output += "\n";
|
|
122
|
+
}
|
|
123
|
+
if (page.bugs != null) {
|
|
124
|
+
output += "\n";
|
|
125
|
+
const bugsLabel = options.colors ? "\x1B[1;2mBugs:\x1B[0m\n" : "Bugs:\n";
|
|
126
|
+
output += bugsLabel;
|
|
127
|
+
const bugsContent = require_message.formatMessage(page.bugs, {
|
|
128
|
+
colors: options.colors,
|
|
129
|
+
maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - 2,
|
|
130
|
+
quotes: !options.colors
|
|
131
|
+
});
|
|
132
|
+
output += " " + indentLines(bugsContent, 2);
|
|
133
|
+
output += "\n";
|
|
134
|
+
}
|
|
95
135
|
if (page.footer != null) {
|
|
96
136
|
output += "\n";
|
|
97
137
|
output += require_message.formatMessage(page.footer, {
|
package/dist/doc.d.cts
CHANGED
|
@@ -43,6 +43,21 @@ interface DocPage {
|
|
|
43
43
|
readonly usage?: Usage;
|
|
44
44
|
readonly description?: Message;
|
|
45
45
|
readonly sections: readonly DocSection[];
|
|
46
|
+
/**
|
|
47
|
+
* Usage examples for the program.
|
|
48
|
+
* @since 0.10.0
|
|
49
|
+
*/
|
|
50
|
+
readonly examples?: Message;
|
|
51
|
+
/**
|
|
52
|
+
* Author information.
|
|
53
|
+
* @since 0.10.0
|
|
54
|
+
*/
|
|
55
|
+
readonly author?: Message;
|
|
56
|
+
/**
|
|
57
|
+
* Information about where to report bugs.
|
|
58
|
+
* @since 0.10.0
|
|
59
|
+
*/
|
|
60
|
+
readonly bugs?: Message;
|
|
46
61
|
readonly footer?: Message;
|
|
47
62
|
}
|
|
48
63
|
/**
|
package/dist/doc.d.ts
CHANGED
|
@@ -43,6 +43,21 @@ interface DocPage {
|
|
|
43
43
|
readonly usage?: Usage;
|
|
44
44
|
readonly description?: Message;
|
|
45
45
|
readonly sections: readonly DocSection[];
|
|
46
|
+
/**
|
|
47
|
+
* Usage examples for the program.
|
|
48
|
+
* @since 0.10.0
|
|
49
|
+
*/
|
|
50
|
+
readonly examples?: Message;
|
|
51
|
+
/**
|
|
52
|
+
* Author information.
|
|
53
|
+
* @since 0.10.0
|
|
54
|
+
*/
|
|
55
|
+
readonly author?: Message;
|
|
56
|
+
/**
|
|
57
|
+
* Information about where to report bugs.
|
|
58
|
+
* @since 0.10.0
|
|
59
|
+
*/
|
|
60
|
+
readonly bugs?: Message;
|
|
46
61
|
readonly footer?: Message;
|
|
47
62
|
}
|
|
48
63
|
/**
|
package/dist/doc.js
CHANGED
|
@@ -46,7 +46,8 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
46
46
|
output += "\n";
|
|
47
47
|
}
|
|
48
48
|
if (page.usage != null) {
|
|
49
|
-
|
|
49
|
+
const usageLabel = options.colors ? "\x1B[1;2mUsage:\x1B[0m " : "Usage: ";
|
|
50
|
+
output += usageLabel;
|
|
50
51
|
output += indentLines(formatUsage(programName, page.usage, {
|
|
51
52
|
colors: options.colors,
|
|
52
53
|
maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - 7,
|
|
@@ -67,7 +68,10 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
67
68
|
for (const section of sections) {
|
|
68
69
|
if (section.entries.length < 1) continue;
|
|
69
70
|
output += "\n";
|
|
70
|
-
if (section.title != null)
|
|
71
|
+
if (section.title != null) {
|
|
72
|
+
const sectionLabel = options.colors ? `\x1b[1;2m${section.title}:\x1b[0m\n` : `${section.title}:\n`;
|
|
73
|
+
output += sectionLabel;
|
|
74
|
+
}
|
|
71
75
|
for (const entry of section.entries) {
|
|
72
76
|
const term = formatUsageTerm(entry.term, {
|
|
73
77
|
colors: options.colors,
|
|
@@ -92,6 +96,42 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
92
96
|
output += `${" ".repeat(termIndent)}${ansiAwareRightPad(term, termWidth)} ${description === "" ? "" : indentLines(description, termIndent + termWidth + 2)}\n`;
|
|
93
97
|
}
|
|
94
98
|
}
|
|
99
|
+
if (page.examples != null) {
|
|
100
|
+
output += "\n";
|
|
101
|
+
const examplesLabel = options.colors ? "\x1B[1;2mExamples:\x1B[0m\n" : "Examples:\n";
|
|
102
|
+
output += examplesLabel;
|
|
103
|
+
const examplesContent = formatMessage(page.examples, {
|
|
104
|
+
colors: options.colors,
|
|
105
|
+
maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - 2,
|
|
106
|
+
quotes: !options.colors
|
|
107
|
+
});
|
|
108
|
+
output += " " + indentLines(examplesContent, 2);
|
|
109
|
+
output += "\n";
|
|
110
|
+
}
|
|
111
|
+
if (page.author != null) {
|
|
112
|
+
output += "\n";
|
|
113
|
+
const authorLabel = options.colors ? "\x1B[1;2mAuthor:\x1B[0m\n" : "Author:\n";
|
|
114
|
+
output += authorLabel;
|
|
115
|
+
const authorContent = formatMessage(page.author, {
|
|
116
|
+
colors: options.colors,
|
|
117
|
+
maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - 2,
|
|
118
|
+
quotes: !options.colors
|
|
119
|
+
});
|
|
120
|
+
output += " " + indentLines(authorContent, 2);
|
|
121
|
+
output += "\n";
|
|
122
|
+
}
|
|
123
|
+
if (page.bugs != null) {
|
|
124
|
+
output += "\n";
|
|
125
|
+
const bugsLabel = options.colors ? "\x1B[1;2mBugs:\x1B[0m\n" : "Bugs:\n";
|
|
126
|
+
output += bugsLabel;
|
|
127
|
+
const bugsContent = formatMessage(page.bugs, {
|
|
128
|
+
colors: options.colors,
|
|
129
|
+
maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - 2,
|
|
130
|
+
quotes: !options.colors
|
|
131
|
+
});
|
|
132
|
+
output += " " + indentLines(bugsContent, 2);
|
|
133
|
+
output += "\n";
|
|
134
|
+
}
|
|
95
135
|
if (page.footer != null) {
|
|
96
136
|
output += "\n";
|
|
97
137
|
output += formatMessage(page.footer, {
|
package/dist/facade.cjs
CHANGED
|
@@ -419,6 +419,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
419
419
|
...options,
|
|
420
420
|
brief: options.brief ?? program.metadata.brief,
|
|
421
421
|
description: options.description ?? program.metadata.description,
|
|
422
|
+
examples: options.examples ?? program.metadata.examples,
|
|
423
|
+
author: options.author ?? program.metadata.author,
|
|
424
|
+
bugs: options.bugs ?? program.metadata.bugs,
|
|
422
425
|
footer: options.footer ?? program.metadata.footer
|
|
423
426
|
};
|
|
424
427
|
} else {
|
|
@@ -429,7 +432,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
429
432
|
}
|
|
430
433
|
const { colors, maxWidth, showDefault, aboveError = "usage", onError = () => {
|
|
431
434
|
throw new RunParserError("Failed to parse command line arguments.");
|
|
432
|
-
}, stderr = console.error, stdout = console.log, brief, description, footer } = options;
|
|
435
|
+
}, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
|
|
433
436
|
const helpMode = options.help?.mode ?? "option";
|
|
434
437
|
const onHelp = options.help?.onShow ?? (() => ({}));
|
|
435
438
|
const versionMode = options.version?.mode ?? "option";
|
|
@@ -530,6 +533,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
530
533
|
...doc,
|
|
531
534
|
brief: !isMetaCommandHelp ? brief ?? doc.brief : doc.brief,
|
|
532
535
|
description: !isMetaCommandHelp ? description ?? doc.description : doc.description,
|
|
536
|
+
examples: !isMetaCommandHelp ? examples ?? doc.examples : doc.examples,
|
|
537
|
+
author: !isMetaCommandHelp ? author ?? doc.author : doc.author,
|
|
538
|
+
bugs: !isMetaCommandHelp ? bugs ?? doc.bugs : doc.bugs,
|
|
533
539
|
footer: !isMetaCommandHelp ? footer ?? doc.footer : doc.footer
|
|
534
540
|
};
|
|
535
541
|
stdout(require_doc.formatDocPage(programName, augmentedDoc, {
|
|
@@ -557,6 +563,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
557
563
|
...doc,
|
|
558
564
|
brief: brief ?? doc.brief,
|
|
559
565
|
description: description ?? doc.description,
|
|
566
|
+
examples: examples ?? doc.examples,
|
|
567
|
+
author: author ?? doc.author,
|
|
568
|
+
bugs: bugs ?? doc.bugs,
|
|
560
569
|
footer: footer ?? doc.footer
|
|
561
570
|
};
|
|
562
571
|
stderr(require_doc.formatDocPage(programName, augmentedDoc, {
|
package/dist/facade.d.cts
CHANGED
|
@@ -178,6 +178,24 @@ interface RunOptions<THelp, TError> {
|
|
|
178
178
|
* @since 0.4.0
|
|
179
179
|
*/
|
|
180
180
|
readonly description?: Message;
|
|
181
|
+
/**
|
|
182
|
+
* Usage examples for the program.
|
|
183
|
+
*
|
|
184
|
+
* @since 0.10.0
|
|
185
|
+
*/
|
|
186
|
+
readonly examples?: Message;
|
|
187
|
+
/**
|
|
188
|
+
* Author information.
|
|
189
|
+
*
|
|
190
|
+
* @since 0.10.0
|
|
191
|
+
*/
|
|
192
|
+
readonly author?: Message;
|
|
193
|
+
/**
|
|
194
|
+
* Information about where to report bugs.
|
|
195
|
+
*
|
|
196
|
+
* @since 0.10.0
|
|
197
|
+
*/
|
|
198
|
+
readonly bugs?: Message;
|
|
181
199
|
/**
|
|
182
200
|
* Footer text shown at the bottom of help text.
|
|
183
201
|
*
|
|
@@ -214,7 +232,7 @@ interface RunOptions<THelp, TError> {
|
|
|
214
232
|
* callbacks.
|
|
215
233
|
* @throws {RunParserError} When parsing fails and no `onError` callback is
|
|
216
234
|
* provided.
|
|
217
|
-
* @since 0.
|
|
235
|
+
* @since 0.10.0 Added support for {@link Program} objects.
|
|
218
236
|
*/
|
|
219
237
|
declare function runParser<T, THelp = void, TError = never>(program: Program<"sync", T>, args: readonly string[], options?: RunOptions<THelp, TError>): T;
|
|
220
238
|
declare function runParser<T, THelp = void, TError = never>(program: Program<"async", T>, args: readonly string[], options?: RunOptions<THelp, TError>): Promise<T>;
|
package/dist/facade.d.ts
CHANGED
|
@@ -178,6 +178,24 @@ interface RunOptions<THelp, TError> {
|
|
|
178
178
|
* @since 0.4.0
|
|
179
179
|
*/
|
|
180
180
|
readonly description?: Message;
|
|
181
|
+
/**
|
|
182
|
+
* Usage examples for the program.
|
|
183
|
+
*
|
|
184
|
+
* @since 0.10.0
|
|
185
|
+
*/
|
|
186
|
+
readonly examples?: Message;
|
|
187
|
+
/**
|
|
188
|
+
* Author information.
|
|
189
|
+
*
|
|
190
|
+
* @since 0.10.0
|
|
191
|
+
*/
|
|
192
|
+
readonly author?: Message;
|
|
193
|
+
/**
|
|
194
|
+
* Information about where to report bugs.
|
|
195
|
+
*
|
|
196
|
+
* @since 0.10.0
|
|
197
|
+
*/
|
|
198
|
+
readonly bugs?: Message;
|
|
181
199
|
/**
|
|
182
200
|
* Footer text shown at the bottom of help text.
|
|
183
201
|
*
|
|
@@ -214,7 +232,7 @@ interface RunOptions<THelp, TError> {
|
|
|
214
232
|
* callbacks.
|
|
215
233
|
* @throws {RunParserError} When parsing fails and no `onError` callback is
|
|
216
234
|
* provided.
|
|
217
|
-
* @since 0.
|
|
235
|
+
* @since 0.10.0 Added support for {@link Program} objects.
|
|
218
236
|
*/
|
|
219
237
|
declare function runParser<T, THelp = void, TError = never>(program: Program<"sync", T>, args: readonly string[], options?: RunOptions<THelp, TError>): T;
|
|
220
238
|
declare function runParser<T, THelp = void, TError = never>(program: Program<"async", T>, args: readonly string[], options?: RunOptions<THelp, TError>): Promise<T>;
|
package/dist/facade.js
CHANGED
|
@@ -419,6 +419,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
419
419
|
...options,
|
|
420
420
|
brief: options.brief ?? program.metadata.brief,
|
|
421
421
|
description: options.description ?? program.metadata.description,
|
|
422
|
+
examples: options.examples ?? program.metadata.examples,
|
|
423
|
+
author: options.author ?? program.metadata.author,
|
|
424
|
+
bugs: options.bugs ?? program.metadata.bugs,
|
|
422
425
|
footer: options.footer ?? program.metadata.footer
|
|
423
426
|
};
|
|
424
427
|
} else {
|
|
@@ -429,7 +432,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
429
432
|
}
|
|
430
433
|
const { colors, maxWidth, showDefault, aboveError = "usage", onError = () => {
|
|
431
434
|
throw new RunParserError("Failed to parse command line arguments.");
|
|
432
|
-
}, stderr = console.error, stdout = console.log, brief, description, footer } = options;
|
|
435
|
+
}, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
|
|
433
436
|
const helpMode = options.help?.mode ?? "option";
|
|
434
437
|
const onHelp = options.help?.onShow ?? (() => ({}));
|
|
435
438
|
const versionMode = options.version?.mode ?? "option";
|
|
@@ -530,6 +533,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
530
533
|
...doc,
|
|
531
534
|
brief: !isMetaCommandHelp ? brief ?? doc.brief : doc.brief,
|
|
532
535
|
description: !isMetaCommandHelp ? description ?? doc.description : doc.description,
|
|
536
|
+
examples: !isMetaCommandHelp ? examples ?? doc.examples : doc.examples,
|
|
537
|
+
author: !isMetaCommandHelp ? author ?? doc.author : doc.author,
|
|
538
|
+
bugs: !isMetaCommandHelp ? bugs ?? doc.bugs : doc.bugs,
|
|
533
539
|
footer: !isMetaCommandHelp ? footer ?? doc.footer : doc.footer
|
|
534
540
|
};
|
|
535
541
|
stdout(formatDocPage(programName, augmentedDoc, {
|
|
@@ -557,6 +563,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
557
563
|
...doc,
|
|
558
564
|
brief: brief ?? doc.brief,
|
|
559
565
|
description: description ?? doc.description,
|
|
566
|
+
examples: examples ?? doc.examples,
|
|
567
|
+
author: author ?? doc.author,
|
|
568
|
+
bugs: bugs ?? doc.bugs,
|
|
560
569
|
footer: footer ?? doc.footer
|
|
561
570
|
};
|
|
562
571
|
stderr(formatDocPage(programName, augmentedDoc, {
|
package/dist/index.cjs
CHANGED
|
@@ -65,6 +65,7 @@ exports.isNonEmptyString = require_nonempty.isNonEmptyString;
|
|
|
65
65
|
exports.isPendingDependencySourceState = require_dependency.isPendingDependencySourceState;
|
|
66
66
|
exports.isValueParser = require_valueparser.isValueParser;
|
|
67
67
|
exports.isWrappedDependencySource = require_dependency.isWrappedDependencySource;
|
|
68
|
+
exports.link = require_message.link;
|
|
68
69
|
exports.locale = require_valueparser.locale;
|
|
69
70
|
exports.longestMatch = require_constructs.longestMatch;
|
|
70
71
|
exports.map = require_modifiers.map;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.cjs";
|
|
2
|
-
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.cjs";
|
|
2
|
+
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.cjs";
|
|
3
3
|
import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.cjs";
|
|
4
4
|
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage } from "./doc.cjs";
|
|
5
5
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.cjs";
|
|
@@ -10,4 +10,4 @@ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOpti
|
|
|
10
10
|
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";
|
|
11
11
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
|
|
12
12
|
import { RunOptions, RunParserError, runParser, runParserAsync, runParserSync } from "./facade.cjs";
|
|
13
|
-
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, 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, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
13
|
+
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, 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, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, link, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
|
|
2
|
-
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
2
|
+
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
3
3
|
import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
|
|
4
4
|
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage } from "./doc.js";
|
|
5
5
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
|
|
@@ -10,4 +10,4 @@ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOpti
|
|
|
10
10
|
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";
|
|
11
11
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
12
12
|
import { RunOptions, RunParserError, runParser, runParserAsync, runParserSync } from "./facade.js";
|
|
13
|
-
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, 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, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
13
|
+
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, 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, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, link, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
1
|
+
import { commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
2
2
|
import { bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
3
3
|
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";
|
|
4
4
|
import { extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
|
|
@@ -11,4 +11,4 @@ import { argument, command, constant, flag, option, passThrough } from "./primit
|
|
|
11
11
|
import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
|
|
12
12
|
import { RunParserError, runParser, runParserAsync, runParserSync } from "./facade.js";
|
|
13
13
|
|
|
14
|
-
export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
14
|
+
export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, link, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, 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,43 @@ function commandLine(commandLine$1) {
|
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
|
+
* Creates a {@link MessageTerm} for a URL.
|
|
144
|
+
* @param url The URL, which can be a URL object or a string that can be parsed
|
|
145
|
+
* as a URL. For example, `"https://example.com"` or
|
|
146
|
+
* `new URL("https://example.com")`.
|
|
147
|
+
* @returns A {@link MessageTerm} representing the URL.
|
|
148
|
+
* @throws {RangeError} If the URL string cannot be parsed.
|
|
149
|
+
* @since 0.10.0
|
|
150
|
+
*/
|
|
151
|
+
function url(url$1) {
|
|
152
|
+
let urlObj;
|
|
153
|
+
if (typeof url$1 === "string") {
|
|
154
|
+
if (!URL.canParse(url$1)) throw new RangeError(`Invalid URL: ${url$1}.`);
|
|
155
|
+
urlObj = new URL(url$1);
|
|
156
|
+
} else urlObj = url$1;
|
|
157
|
+
return {
|
|
158
|
+
type: "url",
|
|
159
|
+
url: urlObj
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Creates a {@link MessageTerm} for a URL (alias for {@link url}).
|
|
164
|
+
*
|
|
165
|
+
* This is an alias for the {@link url} function, provided for convenience
|
|
166
|
+
* when you want to avoid potential naming conflicts with the `url()` value
|
|
167
|
+
* parser from `@optique/core/valueparser`.
|
|
168
|
+
*
|
|
169
|
+
* @param href The URL, which can be a URL object or a string that can be parsed
|
|
170
|
+
* as a URL. For example, `"https://example.com"` or
|
|
171
|
+
* `new URL("https://example.com")`.
|
|
172
|
+
* @returns A {@link MessageTerm} representing the URL.
|
|
173
|
+
* @throws {RangeError} If the URL string cannot be parsed.
|
|
174
|
+
* @since 0.10.0
|
|
175
|
+
*/
|
|
176
|
+
function link(href) {
|
|
177
|
+
return url(href);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
143
180
|
* Creates a {@link Message} for a formatted list of values using the
|
|
144
181
|
* `Intl.ListFormat` API. This is useful for displaying choice lists
|
|
145
182
|
* in error messages with proper locale-aware formatting.
|
|
@@ -295,6 +332,19 @@ function formatMessage(msg, options = {}) {
|
|
|
295
332
|
text: useColors ? `\x1b[36m${cmd}${resetSequence}` : cmd,
|
|
296
333
|
width: cmd.length
|
|
297
334
|
};
|
|
335
|
+
} else if (term.type === "url") {
|
|
336
|
+
const urlString = term.url.href;
|
|
337
|
+
const displayText = useQuotes ? `<${urlString}>` : urlString;
|
|
338
|
+
if (useColors) {
|
|
339
|
+
const hyperlink = `\x1b]8;;${urlString}\x1b\\${displayText}\x1b]8;;\x1b\\${resetSuffix}`;
|
|
340
|
+
yield {
|
|
341
|
+
text: hyperlink,
|
|
342
|
+
width: displayText.length
|
|
343
|
+
};
|
|
344
|
+
} else yield {
|
|
345
|
+
text: displayText,
|
|
346
|
+
width: displayText.length
|
|
347
|
+
};
|
|
298
348
|
} else throw new TypeError(`Invalid MessageTerm type: ${term["type"]}.`);
|
|
299
349
|
}
|
|
300
350
|
let output = "";
|
|
@@ -319,11 +369,13 @@ function formatMessage(msg, options = {}) {
|
|
|
319
369
|
exports.commandLine = commandLine;
|
|
320
370
|
exports.envVar = envVar;
|
|
321
371
|
exports.formatMessage = formatMessage;
|
|
372
|
+
exports.link = link;
|
|
322
373
|
exports.message = message;
|
|
323
374
|
exports.metavar = metavar;
|
|
324
375
|
exports.optionName = optionName;
|
|
325
376
|
exports.optionNames = optionNames;
|
|
326
377
|
exports.text = text;
|
|
378
|
+
exports.url = url;
|
|
327
379
|
exports.value = value;
|
|
328
380
|
exports.valueSet = valueSet;
|
|
329
381
|
exports.values = values;
|
package/dist/message.d.cts
CHANGED
|
@@ -122,6 +122,19 @@ type MessageTerm =
|
|
|
122
122
|
* For example, `"myapp completion bash > myapp-completion.bash"`.
|
|
123
123
|
*/
|
|
124
124
|
readonly commandLine: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A URL term in the message, which represents a clickable hyperlink.
|
|
128
|
+
* @since 0.10.0
|
|
129
|
+
*/ | {
|
|
130
|
+
/**
|
|
131
|
+
* The type of the term, which is `"url"` for a URL.
|
|
132
|
+
*/
|
|
133
|
+
readonly type: "url";
|
|
134
|
+
/**
|
|
135
|
+
* The URL object representing the hyperlink.
|
|
136
|
+
*/
|
|
137
|
+
readonly url: URL;
|
|
125
138
|
};
|
|
126
139
|
/**
|
|
127
140
|
* Type representing a message that can include styled/colored values.
|
|
@@ -210,6 +223,31 @@ declare function envVar(envVar: string): MessageTerm;
|
|
|
210
223
|
* @since 0.6.0
|
|
211
224
|
*/
|
|
212
225
|
declare function commandLine(commandLine: string): MessageTerm;
|
|
226
|
+
/**
|
|
227
|
+
* Creates a {@link MessageTerm} for a URL.
|
|
228
|
+
* @param url The URL, which can be a URL object or a string that can be parsed
|
|
229
|
+
* as a URL. For example, `"https://example.com"` or
|
|
230
|
+
* `new URL("https://example.com")`.
|
|
231
|
+
* @returns A {@link MessageTerm} representing the URL.
|
|
232
|
+
* @throws {RangeError} If the URL string cannot be parsed.
|
|
233
|
+
* @since 0.10.0
|
|
234
|
+
*/
|
|
235
|
+
declare function url(url: string | URL): MessageTerm;
|
|
236
|
+
/**
|
|
237
|
+
* Creates a {@link MessageTerm} for a URL (alias for {@link url}).
|
|
238
|
+
*
|
|
239
|
+
* This is an alias for the {@link url} function, provided for convenience
|
|
240
|
+
* when you want to avoid potential naming conflicts with the `url()` value
|
|
241
|
+
* parser from `@optique/core/valueparser`.
|
|
242
|
+
*
|
|
243
|
+
* @param href The URL, which can be a URL object or a string that can be parsed
|
|
244
|
+
* as a URL. For example, `"https://example.com"` or
|
|
245
|
+
* `new URL("https://example.com")`.
|
|
246
|
+
* @returns A {@link MessageTerm} representing the URL.
|
|
247
|
+
* @throws {RangeError} If the URL string cannot be parsed.
|
|
248
|
+
* @since 0.10.0
|
|
249
|
+
*/
|
|
250
|
+
declare function link(href: string | URL): MessageTerm;
|
|
213
251
|
/**
|
|
214
252
|
* Options for the {@link valueSet} function.
|
|
215
253
|
* @since 0.9.0
|
|
@@ -323,4 +361,4 @@ interface MessageFormatOptions {
|
|
|
323
361
|
*/
|
|
324
362
|
declare function formatMessage(msg: Message, options?: MessageFormatOptions): string;
|
|
325
363
|
//#endregion
|
|
326
|
-
export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values };
|
|
364
|
+
export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
package/dist/message.d.ts
CHANGED
|
@@ -122,6 +122,19 @@ type MessageTerm =
|
|
|
122
122
|
* For example, `"myapp completion bash > myapp-completion.bash"`.
|
|
123
123
|
*/
|
|
124
124
|
readonly commandLine: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A URL term in the message, which represents a clickable hyperlink.
|
|
128
|
+
* @since 0.10.0
|
|
129
|
+
*/ | {
|
|
130
|
+
/**
|
|
131
|
+
* The type of the term, which is `"url"` for a URL.
|
|
132
|
+
*/
|
|
133
|
+
readonly type: "url";
|
|
134
|
+
/**
|
|
135
|
+
* The URL object representing the hyperlink.
|
|
136
|
+
*/
|
|
137
|
+
readonly url: URL;
|
|
125
138
|
};
|
|
126
139
|
/**
|
|
127
140
|
* Type representing a message that can include styled/colored values.
|
|
@@ -210,6 +223,31 @@ declare function envVar(envVar: string): MessageTerm;
|
|
|
210
223
|
* @since 0.6.0
|
|
211
224
|
*/
|
|
212
225
|
declare function commandLine(commandLine: string): MessageTerm;
|
|
226
|
+
/**
|
|
227
|
+
* Creates a {@link MessageTerm} for a URL.
|
|
228
|
+
* @param url The URL, which can be a URL object or a string that can be parsed
|
|
229
|
+
* as a URL. For example, `"https://example.com"` or
|
|
230
|
+
* `new URL("https://example.com")`.
|
|
231
|
+
* @returns A {@link MessageTerm} representing the URL.
|
|
232
|
+
* @throws {RangeError} If the URL string cannot be parsed.
|
|
233
|
+
* @since 0.10.0
|
|
234
|
+
*/
|
|
235
|
+
declare function url(url: string | URL): MessageTerm;
|
|
236
|
+
/**
|
|
237
|
+
* Creates a {@link MessageTerm} for a URL (alias for {@link url}).
|
|
238
|
+
*
|
|
239
|
+
* This is an alias for the {@link url} function, provided for convenience
|
|
240
|
+
* when you want to avoid potential naming conflicts with the `url()` value
|
|
241
|
+
* parser from `@optique/core/valueparser`.
|
|
242
|
+
*
|
|
243
|
+
* @param href The URL, which can be a URL object or a string that can be parsed
|
|
244
|
+
* as a URL. For example, `"https://example.com"` or
|
|
245
|
+
* `new URL("https://example.com")`.
|
|
246
|
+
* @returns A {@link MessageTerm} representing the URL.
|
|
247
|
+
* @throws {RangeError} If the URL string cannot be parsed.
|
|
248
|
+
* @since 0.10.0
|
|
249
|
+
*/
|
|
250
|
+
declare function link(href: string | URL): MessageTerm;
|
|
213
251
|
/**
|
|
214
252
|
* Options for the {@link valueSet} function.
|
|
215
253
|
* @since 0.9.0
|
|
@@ -323,4 +361,4 @@ interface MessageFormatOptions {
|
|
|
323
361
|
*/
|
|
324
362
|
declare function formatMessage(msg: Message, options?: MessageFormatOptions): string;
|
|
325
363
|
//#endregion
|
|
326
|
-
export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values };
|
|
364
|
+
export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
package/dist/message.js
CHANGED
|
@@ -139,6 +139,43 @@ function commandLine(commandLine$1) {
|
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
|
+
* Creates a {@link MessageTerm} for a URL.
|
|
143
|
+
* @param url The URL, which can be a URL object or a string that can be parsed
|
|
144
|
+
* as a URL. For example, `"https://example.com"` or
|
|
145
|
+
* `new URL("https://example.com")`.
|
|
146
|
+
* @returns A {@link MessageTerm} representing the URL.
|
|
147
|
+
* @throws {RangeError} If the URL string cannot be parsed.
|
|
148
|
+
* @since 0.10.0
|
|
149
|
+
*/
|
|
150
|
+
function url(url$1) {
|
|
151
|
+
let urlObj;
|
|
152
|
+
if (typeof url$1 === "string") {
|
|
153
|
+
if (!URL.canParse(url$1)) throw new RangeError(`Invalid URL: ${url$1}.`);
|
|
154
|
+
urlObj = new URL(url$1);
|
|
155
|
+
} else urlObj = url$1;
|
|
156
|
+
return {
|
|
157
|
+
type: "url",
|
|
158
|
+
url: urlObj
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Creates a {@link MessageTerm} for a URL (alias for {@link url}).
|
|
163
|
+
*
|
|
164
|
+
* This is an alias for the {@link url} function, provided for convenience
|
|
165
|
+
* when you want to avoid potential naming conflicts with the `url()` value
|
|
166
|
+
* parser from `@optique/core/valueparser`.
|
|
167
|
+
*
|
|
168
|
+
* @param href The URL, which can be a URL object or a string that can be parsed
|
|
169
|
+
* as a URL. For example, `"https://example.com"` or
|
|
170
|
+
* `new URL("https://example.com")`.
|
|
171
|
+
* @returns A {@link MessageTerm} representing the URL.
|
|
172
|
+
* @throws {RangeError} If the URL string cannot be parsed.
|
|
173
|
+
* @since 0.10.0
|
|
174
|
+
*/
|
|
175
|
+
function link(href) {
|
|
176
|
+
return url(href);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
142
179
|
* Creates a {@link Message} for a formatted list of values using the
|
|
143
180
|
* `Intl.ListFormat` API. This is useful for displaying choice lists
|
|
144
181
|
* in error messages with proper locale-aware formatting.
|
|
@@ -294,6 +331,19 @@ function formatMessage(msg, options = {}) {
|
|
|
294
331
|
text: useColors ? `\x1b[36m${cmd}${resetSequence}` : cmd,
|
|
295
332
|
width: cmd.length
|
|
296
333
|
};
|
|
334
|
+
} else if (term.type === "url") {
|
|
335
|
+
const urlString = term.url.href;
|
|
336
|
+
const displayText = useQuotes ? `<${urlString}>` : urlString;
|
|
337
|
+
if (useColors) {
|
|
338
|
+
const hyperlink = `\x1b]8;;${urlString}\x1b\\${displayText}\x1b]8;;\x1b\\${resetSuffix}`;
|
|
339
|
+
yield {
|
|
340
|
+
text: hyperlink,
|
|
341
|
+
width: displayText.length
|
|
342
|
+
};
|
|
343
|
+
} else yield {
|
|
344
|
+
text: displayText,
|
|
345
|
+
width: displayText.length
|
|
346
|
+
};
|
|
297
347
|
} else throw new TypeError(`Invalid MessageTerm type: ${term["type"]}.`);
|
|
298
348
|
}
|
|
299
349
|
let output = "";
|
|
@@ -315,4 +365,4 @@ function formatMessage(msg, options = {}) {
|
|
|
315
365
|
}
|
|
316
366
|
|
|
317
367
|
//#endregion
|
|
318
|
-
export { commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values };
|
|
368
|
+
export { commandLine, envVar, formatMessage, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
package/dist/program.d.cts
CHANGED
package/dist/program.d.ts
CHANGED