@optique/core 0.10.4 → 0.10.5
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 +38 -8
- package/dist/doc.js +38 -8
- package/dist/facade.cjs +6 -0
- package/dist/facade.js +6 -0
- package/dist/message.cjs +1 -9
- package/dist/message.js +1 -9
- package/package.json +1 -1
package/dist/doc.cjs
CHANGED
|
@@ -78,18 +78,31 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
78
78
|
optionsSeparator: ", ",
|
|
79
79
|
maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent
|
|
80
80
|
});
|
|
81
|
+
const descColumnWidth = options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2;
|
|
81
82
|
let description = entry.description == null ? "" : require_message.formatMessage(entry.description, {
|
|
82
83
|
colors: options.colors,
|
|
83
84
|
quotes: !options.colors,
|
|
84
|
-
maxWidth:
|
|
85
|
+
maxWidth: descColumnWidth
|
|
85
86
|
});
|
|
86
87
|
if (options.showDefault && entry.default != null) {
|
|
87
88
|
const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
|
|
88
89
|
const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
|
|
89
|
-
|
|
90
|
+
let defaultStartWidth;
|
|
91
|
+
if (descColumnWidth != null) {
|
|
92
|
+
const lastW = lastLineVisibleLength(description);
|
|
93
|
+
if (lastW + prefix.length >= descColumnWidth) {
|
|
94
|
+
description += "\n";
|
|
95
|
+
defaultStartWidth = prefix.length;
|
|
96
|
+
} else defaultStartWidth = lastW + prefix.length;
|
|
97
|
+
}
|
|
98
|
+
const defaultFormatOptions = {
|
|
90
99
|
colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
|
|
91
|
-
quotes: !options.colors
|
|
92
|
-
|
|
100
|
+
quotes: !options.colors,
|
|
101
|
+
maxWidth: descColumnWidth,
|
|
102
|
+
startWidth: defaultStartWidth
|
|
103
|
+
};
|
|
104
|
+
const defaultContent = require_message.formatMessage(entry.default, defaultFormatOptions);
|
|
105
|
+
const defaultText = `${prefix}${defaultContent}${suffix}`;
|
|
93
106
|
const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
|
|
94
107
|
description += formattedDefault;
|
|
95
108
|
}
|
|
@@ -114,10 +127,22 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
114
127
|
}
|
|
115
128
|
if (truncated) truncatedTerms = [...terms.slice(0, cutIndex), require_message.text(", ...")];
|
|
116
129
|
}
|
|
117
|
-
|
|
130
|
+
let choicesStartWidth;
|
|
131
|
+
if (descColumnWidth != null) {
|
|
132
|
+
const lastW = lastLineVisibleLength(description);
|
|
133
|
+
const prefixLabelLen = prefix.length + label.length;
|
|
134
|
+
if (lastW + prefixLabelLen >= descColumnWidth) {
|
|
135
|
+
description += "\n";
|
|
136
|
+
choicesStartWidth = prefixLabelLen;
|
|
137
|
+
} else choicesStartWidth = lastW + prefixLabelLen;
|
|
138
|
+
}
|
|
139
|
+
const choicesFormatOptions = {
|
|
118
140
|
colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
|
|
119
|
-
quotes: false
|
|
120
|
-
|
|
141
|
+
quotes: false,
|
|
142
|
+
maxWidth: descColumnWidth,
|
|
143
|
+
startWidth: choicesStartWidth
|
|
144
|
+
};
|
|
145
|
+
const choicesDisplay = require_message.formatMessage(truncatedTerms, choicesFormatOptions);
|
|
121
146
|
const choicesText = `${prefix}${label}${choicesDisplay}${suffix}`;
|
|
122
147
|
const formattedChoices = options.colors ? `\x1b[2m${choicesText}\x1b[0m` : choicesText;
|
|
123
148
|
description += formattedChoices;
|
|
@@ -174,12 +199,17 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
174
199
|
function indentLines(text$1, indent) {
|
|
175
200
|
return text$1.split("\n").join("\n" + " ".repeat(indent));
|
|
176
201
|
}
|
|
202
|
+
const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
|
|
177
203
|
function ansiAwareRightPad(text$1, length, char = " ") {
|
|
178
|
-
const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
|
|
179
204
|
const strippedText = text$1.replace(ansiEscapeCodeRegex, "");
|
|
180
205
|
if (strippedText.length >= length) return text$1;
|
|
181
206
|
return text$1 + char.repeat(length - strippedText.length);
|
|
182
207
|
}
|
|
208
|
+
function lastLineVisibleLength(text$1) {
|
|
209
|
+
const lastNewline = text$1.lastIndexOf("\n");
|
|
210
|
+
const lastLine = lastNewline === -1 ? text$1 : text$1.slice(lastNewline + 1);
|
|
211
|
+
return lastLine.replace(ansiEscapeCodeRegex, "").length;
|
|
212
|
+
}
|
|
183
213
|
|
|
184
214
|
//#endregion
|
|
185
215
|
exports.formatDocPage = formatDocPage;
|
package/dist/doc.js
CHANGED
|
@@ -78,18 +78,31 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
78
78
|
optionsSeparator: ", ",
|
|
79
79
|
maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent
|
|
80
80
|
});
|
|
81
|
+
const descColumnWidth = options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2;
|
|
81
82
|
let description = entry.description == null ? "" : formatMessage(entry.description, {
|
|
82
83
|
colors: options.colors,
|
|
83
84
|
quotes: !options.colors,
|
|
84
|
-
maxWidth:
|
|
85
|
+
maxWidth: descColumnWidth
|
|
85
86
|
});
|
|
86
87
|
if (options.showDefault && entry.default != null) {
|
|
87
88
|
const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
|
|
88
89
|
const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
|
|
89
|
-
|
|
90
|
+
let defaultStartWidth;
|
|
91
|
+
if (descColumnWidth != null) {
|
|
92
|
+
const lastW = lastLineVisibleLength(description);
|
|
93
|
+
if (lastW + prefix.length >= descColumnWidth) {
|
|
94
|
+
description += "\n";
|
|
95
|
+
defaultStartWidth = prefix.length;
|
|
96
|
+
} else defaultStartWidth = lastW + prefix.length;
|
|
97
|
+
}
|
|
98
|
+
const defaultFormatOptions = {
|
|
90
99
|
colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
|
|
91
|
-
quotes: !options.colors
|
|
92
|
-
|
|
100
|
+
quotes: !options.colors,
|
|
101
|
+
maxWidth: descColumnWidth,
|
|
102
|
+
startWidth: defaultStartWidth
|
|
103
|
+
};
|
|
104
|
+
const defaultContent = formatMessage(entry.default, defaultFormatOptions);
|
|
105
|
+
const defaultText = `${prefix}${defaultContent}${suffix}`;
|
|
93
106
|
const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
|
|
94
107
|
description += formattedDefault;
|
|
95
108
|
}
|
|
@@ -114,10 +127,22 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
114
127
|
}
|
|
115
128
|
if (truncated) truncatedTerms = [...terms.slice(0, cutIndex), text(", ...")];
|
|
116
129
|
}
|
|
117
|
-
|
|
130
|
+
let choicesStartWidth;
|
|
131
|
+
if (descColumnWidth != null) {
|
|
132
|
+
const lastW = lastLineVisibleLength(description);
|
|
133
|
+
const prefixLabelLen = prefix.length + label.length;
|
|
134
|
+
if (lastW + prefixLabelLen >= descColumnWidth) {
|
|
135
|
+
description += "\n";
|
|
136
|
+
choicesStartWidth = prefixLabelLen;
|
|
137
|
+
} else choicesStartWidth = lastW + prefixLabelLen;
|
|
138
|
+
}
|
|
139
|
+
const choicesFormatOptions = {
|
|
118
140
|
colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
|
|
119
|
-
quotes: false
|
|
120
|
-
|
|
141
|
+
quotes: false,
|
|
142
|
+
maxWidth: descColumnWidth,
|
|
143
|
+
startWidth: choicesStartWidth
|
|
144
|
+
};
|
|
145
|
+
const choicesDisplay = formatMessage(truncatedTerms, choicesFormatOptions);
|
|
121
146
|
const choicesText = `${prefix}${label}${choicesDisplay}${suffix}`;
|
|
122
147
|
const formattedChoices = options.colors ? `\x1b[2m${choicesText}\x1b[0m` : choicesText;
|
|
123
148
|
description += formattedChoices;
|
|
@@ -174,12 +199,17 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
174
199
|
function indentLines(text$1, indent) {
|
|
175
200
|
return text$1.split("\n").join("\n" + " ".repeat(indent));
|
|
176
201
|
}
|
|
202
|
+
const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
|
|
177
203
|
function ansiAwareRightPad(text$1, length, char = " ") {
|
|
178
|
-
const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
|
|
179
204
|
const strippedText = text$1.replace(ansiEscapeCodeRegex, "");
|
|
180
205
|
if (strippedText.length >= length) return text$1;
|
|
181
206
|
return text$1 + char.repeat(length - strippedText.length);
|
|
182
207
|
}
|
|
208
|
+
function lastLineVisibleLength(text$1) {
|
|
209
|
+
const lastNewline = text$1.lastIndexOf("\n");
|
|
210
|
+
const lastLine = lastNewline === -1 ? text$1 : text$1.slice(lastNewline + 1);
|
|
211
|
+
return lastLine.replace(ansiEscapeCodeRegex, "").length;
|
|
212
|
+
}
|
|
183
213
|
|
|
184
214
|
//#endregion
|
|
185
215
|
export { formatDocPage };
|
package/dist/facade.cjs
CHANGED
|
@@ -542,6 +542,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
542
542
|
const helpAsCommand = help === "command" || help === "both";
|
|
543
543
|
const versionAsCommand = version === "command" || version === "both";
|
|
544
544
|
const completionAsCommand = completion === "command" || completion === "both";
|
|
545
|
+
const helpAsOption = help === "option" || help === "both";
|
|
546
|
+
const versionAsOption = version === "option" || version === "both";
|
|
547
|
+
const completionAsOption = completion === "option" || completion === "both";
|
|
545
548
|
const requestedCommand = classified.commands[0];
|
|
546
549
|
if ((requestedCommand === "completion" || requestedCommand === "completions") && completionAsCommand && completionParsers.completionCommand) helpGeneratorParser = completionParsers.completionCommand;
|
|
547
550
|
else if (requestedCommand === "help" && helpAsCommand && helpParsers.helpCommand) helpGeneratorParser = helpParsers.helpCommand;
|
|
@@ -560,6 +563,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
560
563
|
commandParsers.push(...ungroupedMeta);
|
|
561
564
|
for (const [label, parsers] of Object.entries(groupedMeta)) if (parsers.length === 1) commandParsers.push(require_constructs.group(label, parsers[0]));
|
|
562
565
|
else commandParsers.push(require_constructs.group(label, require_constructs.longestMatch(...parsers)));
|
|
566
|
+
if (helpAsOption && helpParsers.helpOption) commandParsers.push(helpParsers.helpOption);
|
|
567
|
+
if (versionAsOption && versionParsers.versionOption) commandParsers.push(versionParsers.versionOption);
|
|
568
|
+
if (completionAsOption && completionParsers.completionOption) commandParsers.push(completionParsers.completionOption);
|
|
563
569
|
if (commandParsers.length === 1) helpGeneratorParser = commandParsers[0];
|
|
564
570
|
else if (commandParsers.length === 2) helpGeneratorParser = require_constructs.longestMatch(commandParsers[0], commandParsers[1]);
|
|
565
571
|
else helpGeneratorParser = require_constructs.longestMatch(...commandParsers);
|
package/dist/facade.js
CHANGED
|
@@ -542,6 +542,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
542
542
|
const helpAsCommand = help === "command" || help === "both";
|
|
543
543
|
const versionAsCommand = version === "command" || version === "both";
|
|
544
544
|
const completionAsCommand = completion === "command" || completion === "both";
|
|
545
|
+
const helpAsOption = help === "option" || help === "both";
|
|
546
|
+
const versionAsOption = version === "option" || version === "both";
|
|
547
|
+
const completionAsOption = completion === "option" || completion === "both";
|
|
545
548
|
const requestedCommand = classified.commands[0];
|
|
546
549
|
if ((requestedCommand === "completion" || requestedCommand === "completions") && completionAsCommand && completionParsers.completionCommand) helpGeneratorParser = completionParsers.completionCommand;
|
|
547
550
|
else if (requestedCommand === "help" && helpAsCommand && helpParsers.helpCommand) helpGeneratorParser = helpParsers.helpCommand;
|
|
@@ -560,6 +563,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
560
563
|
commandParsers.push(...ungroupedMeta);
|
|
561
564
|
for (const [label, parsers] of Object.entries(groupedMeta)) if (parsers.length === 1) commandParsers.push(group(label, parsers[0]));
|
|
562
565
|
else commandParsers.push(group(label, longestMatch(...parsers)));
|
|
566
|
+
if (helpAsOption && helpParsers.helpOption) commandParsers.push(helpParsers.helpOption);
|
|
567
|
+
if (versionAsOption && versionParsers.versionOption) commandParsers.push(versionParsers.versionOption);
|
|
568
|
+
if (completionAsOption && completionParsers.completionOption) commandParsers.push(completionParsers.completionOption);
|
|
563
569
|
if (commandParsers.length === 1) helpGeneratorParser = commandParsers[0];
|
|
564
570
|
else if (commandParsers.length === 2) helpGeneratorParser = longestMatch(commandParsers[0], commandParsers[1]);
|
|
565
571
|
else helpGeneratorParser = longestMatch(...commandParsers);
|
package/dist/message.cjs
CHANGED
|
@@ -237,14 +237,6 @@ function valueSet(values$1, options) {
|
|
|
237
237
|
});
|
|
238
238
|
return result;
|
|
239
239
|
}
|
|
240
|
-
/**
|
|
241
|
-
* Formats a {@link Message} into a human-readable string for
|
|
242
|
-
* the terminal.
|
|
243
|
-
* @param msg The message to format, which is an array of
|
|
244
|
-
* {@link MessageTerm} objects.
|
|
245
|
-
* @param options Optional formatting options to customize the output.
|
|
246
|
-
* @returns A formatted string representation of the message.
|
|
247
|
-
*/
|
|
248
240
|
function formatMessage(msg, options = {}) {
|
|
249
241
|
const colorConfig = options.colors ?? false;
|
|
250
242
|
const useColors = typeof colorConfig === "boolean" ? colorConfig : true;
|
|
@@ -373,7 +365,7 @@ function formatMessage(msg, options = {}) {
|
|
|
373
365
|
}
|
|
374
366
|
}
|
|
375
367
|
let output = "";
|
|
376
|
-
let totalWidth = 0;
|
|
368
|
+
let totalWidth = options.startWidth ?? 0;
|
|
377
369
|
for (const { text: text$1, width } of stream()) {
|
|
378
370
|
if (width === -1) {
|
|
379
371
|
output += text$1;
|
package/dist/message.js
CHANGED
|
@@ -236,14 +236,6 @@ function valueSet(values$1, options) {
|
|
|
236
236
|
});
|
|
237
237
|
return result;
|
|
238
238
|
}
|
|
239
|
-
/**
|
|
240
|
-
* Formats a {@link Message} into a human-readable string for
|
|
241
|
-
* the terminal.
|
|
242
|
-
* @param msg The message to format, which is an array of
|
|
243
|
-
* {@link MessageTerm} objects.
|
|
244
|
-
* @param options Optional formatting options to customize the output.
|
|
245
|
-
* @returns A formatted string representation of the message.
|
|
246
|
-
*/
|
|
247
239
|
function formatMessage(msg, options = {}) {
|
|
248
240
|
const colorConfig = options.colors ?? false;
|
|
249
241
|
const useColors = typeof colorConfig === "boolean" ? colorConfig : true;
|
|
@@ -372,7 +364,7 @@ function formatMessage(msg, options = {}) {
|
|
|
372
364
|
}
|
|
373
365
|
}
|
|
374
366
|
let output = "";
|
|
375
|
-
let totalWidth = 0;
|
|
367
|
+
let totalWidth = options.startWidth ?? 0;
|
|
376
368
|
for (const { text: text$1, width } of stream()) {
|
|
377
369
|
if (width === -1) {
|
|
378
370
|
output += text$1;
|