@optique/run 1.3.0-dev.2529 → 1.3.0-dev.2530
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/print.cjs +24 -11
- package/dist/print.d.cts +12 -1
- package/dist/print.d.ts +12 -1
- package/dist/print.js +28 -15
- package/dist/run.cjs +2 -0
- package/dist/run.d.cts +6 -1
- package/dist/run.d.ts +6 -1
- package/dist/run.js +2 -0
- package/package.json +4 -4
package/dist/print.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const node_process = require_rolldown_runtime.__toESM(require("node:process"));
|
|
3
|
-
const
|
|
3
|
+
const __optique_core_internal_terminal = require_rolldown_runtime.__toESM(require("@optique/core/internal/terminal"));
|
|
4
4
|
|
|
5
5
|
//#region src/print.ts
|
|
6
6
|
/**
|
|
@@ -29,6 +29,7 @@ const __optique_core_message = require_rolldown_runtime.__toESM(require("@optiqu
|
|
|
29
29
|
*/
|
|
30
30
|
function print(message, options = {}) {
|
|
31
31
|
const printer = createPrinter({
|
|
32
|
+
...options,
|
|
32
33
|
stream: options.stream ?? "stdout",
|
|
33
34
|
colors: options.colors,
|
|
34
35
|
quotes: options.quotes,
|
|
@@ -40,17 +41,27 @@ function printError(message, options = {}) {
|
|
|
40
41
|
const stream = options.stream ?? "stderr";
|
|
41
42
|
const output = node_process.default[stream];
|
|
42
43
|
const quotes = options.quotes ?? !output.isTTY;
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const colors = options.colors ?? output.isTTY;
|
|
45
|
+
const useColors = typeof colors === "object" ? true : colors;
|
|
46
|
+
const maxWidth = options.maxWidth ?? output.columns;
|
|
47
|
+
const occupied = options.initialWidth ?? 0;
|
|
48
|
+
if (!Number.isFinite(occupied) || !Number.isInteger(occupied)) throw new TypeError("Initial width must be a finite integer.");
|
|
49
|
+
if (occupied < 0) throw new RangeError("Initial width must be nonnegative.");
|
|
50
|
+
let prefix = (0, __optique_core_internal_terminal.renderTerminalTerm)({
|
|
51
|
+
type: "errorLabel",
|
|
52
|
+
label: "Error:"
|
|
53
|
+
}, options.theme, useColors) + " ";
|
|
54
|
+
if (maxWidth != null && occupied > 0 && occupied + (0, __optique_core_internal_terminal.getDisplayWidth)(prefix.split("\n")[0]) > maxWidth) prefix = "\n" + prefix;
|
|
55
|
+
const prefixLines = prefix.split("\n");
|
|
56
|
+
const initialWidth = (0, __optique_core_internal_terminal.getDisplayWidth)(prefixLines.at(-1) ?? "") + (prefixLines.length === 1 ? options.initialWidth ?? 0 : 0);
|
|
57
|
+
const formatMessage = (0, __optique_core_internal_terminal.resolveMessageFormatter)(options);
|
|
58
|
+
const formatted = formatMessage(message, {
|
|
59
|
+
colors,
|
|
46
60
|
quotes,
|
|
47
|
-
maxWidth
|
|
61
|
+
maxWidth,
|
|
62
|
+
initialWidth
|
|
48
63
|
});
|
|
49
|
-
|
|
50
|
-
type: "text",
|
|
51
|
-
text: "Error: "
|
|
52
|
-
}, ...message];
|
|
53
|
-
printer(errorMessage);
|
|
64
|
+
output.write(prefix + formatted + "\n");
|
|
54
65
|
if (options.exitCode != null) node_process.default.exit(options.exitCode);
|
|
55
66
|
}
|
|
56
67
|
/**
|
|
@@ -83,13 +94,15 @@ function printError(message, options = {}) {
|
|
|
83
94
|
function createPrinter(options = {}) {
|
|
84
95
|
const stream = options.stream ?? "stdout";
|
|
85
96
|
const output = node_process.default[stream];
|
|
97
|
+
const formatMessage = (0, __optique_core_internal_terminal.resolveMessageFormatter)(options);
|
|
86
98
|
const formatOptions = {
|
|
99
|
+
initialWidth: options.initialWidth,
|
|
87
100
|
colors: options.colors ?? output.isTTY,
|
|
88
101
|
quotes: options.quotes,
|
|
89
102
|
maxWidth: options.maxWidth ?? output.columns
|
|
90
103
|
};
|
|
91
104
|
return (message) => {
|
|
92
|
-
const formatted =
|
|
105
|
+
const formatted = formatMessage(message, formatOptions);
|
|
93
106
|
if (stream === "stderr") node_process.default.stderr.write(formatted + "\n");
|
|
94
107
|
else node_process.default.stdout.write(formatted + "\n");
|
|
95
108
|
};
|
package/dist/print.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Message, MessageFormatOptions } from "@optique/core/message";
|
|
1
|
+
import { Message, MessageFormatOptions, MessageFormatter } from "@optique/core/message";
|
|
2
|
+
import { TerminalTheme } from "@optique/core/terminal";
|
|
2
3
|
|
|
3
4
|
//#region src/print.d.ts
|
|
4
5
|
|
|
@@ -7,6 +8,10 @@ import { Message, MessageFormatOptions } from "@optique/core/message";
|
|
|
7
8
|
* @since 0.3.0
|
|
8
9
|
*/
|
|
9
10
|
interface PrintOptions extends MessageFormatOptions {
|
|
11
|
+
/** Custom message renderer, taking precedence over theme for messages. @since 1.3.0 */
|
|
12
|
+
readonly messageFormatter?: MessageFormatter;
|
|
13
|
+
/** Semantic terminal theme. @since 1.3.0 */
|
|
14
|
+
readonly theme?: TerminalTheme;
|
|
10
15
|
/**
|
|
11
16
|
* The output stream to write to.
|
|
12
17
|
* @default `"stdout"`
|
|
@@ -34,6 +39,10 @@ interface PrintErrorOptions extends PrintOptions {
|
|
|
34
39
|
* @since 0.3.0
|
|
35
40
|
*/
|
|
36
41
|
interface PrinterOptions extends MessageFormatOptions {
|
|
42
|
+
/** Custom message renderer, taking precedence over theme for messages. @since 1.3.0 */
|
|
43
|
+
readonly messageFormatter?: MessageFormatter;
|
|
44
|
+
/** Semantic terminal theme. @since 1.3.0 */
|
|
45
|
+
readonly theme?: TerminalTheme;
|
|
37
46
|
/**
|
|
38
47
|
* The output stream to write to.
|
|
39
48
|
* @default `"stdout"`
|
|
@@ -80,6 +89,8 @@ declare function print(message: Message, options?: PrintOptions): void;
|
|
|
80
89
|
*
|
|
81
90
|
* @param message The structured error message to print.
|
|
82
91
|
* @param options Optional formatting options and exit code.
|
|
92
|
+
* @throws {TypeError} If initialWidth is not a finite integer.
|
|
93
|
+
* @throws {RangeError} If initialWidth is negative or a theme color is invalid.
|
|
83
94
|
*
|
|
84
95
|
* @example
|
|
85
96
|
* ```typescript
|
package/dist/print.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Message, MessageFormatOptions } from "@optique/core/message";
|
|
1
|
+
import { Message, MessageFormatOptions, MessageFormatter } from "@optique/core/message";
|
|
2
|
+
import { TerminalTheme } from "@optique/core/terminal";
|
|
2
3
|
|
|
3
4
|
//#region src/print.d.ts
|
|
4
5
|
|
|
@@ -7,6 +8,10 @@ import { Message, MessageFormatOptions } from "@optique/core/message";
|
|
|
7
8
|
* @since 0.3.0
|
|
8
9
|
*/
|
|
9
10
|
interface PrintOptions extends MessageFormatOptions {
|
|
11
|
+
/** Custom message renderer, taking precedence over theme for messages. @since 1.3.0 */
|
|
12
|
+
readonly messageFormatter?: MessageFormatter;
|
|
13
|
+
/** Semantic terminal theme. @since 1.3.0 */
|
|
14
|
+
readonly theme?: TerminalTheme;
|
|
10
15
|
/**
|
|
11
16
|
* The output stream to write to.
|
|
12
17
|
* @default `"stdout"`
|
|
@@ -34,6 +39,10 @@ interface PrintErrorOptions extends PrintOptions {
|
|
|
34
39
|
* @since 0.3.0
|
|
35
40
|
*/
|
|
36
41
|
interface PrinterOptions extends MessageFormatOptions {
|
|
42
|
+
/** Custom message renderer, taking precedence over theme for messages. @since 1.3.0 */
|
|
43
|
+
readonly messageFormatter?: MessageFormatter;
|
|
44
|
+
/** Semantic terminal theme. @since 1.3.0 */
|
|
45
|
+
readonly theme?: TerminalTheme;
|
|
37
46
|
/**
|
|
38
47
|
* The output stream to write to.
|
|
39
48
|
* @default `"stdout"`
|
|
@@ -80,6 +89,8 @@ declare function print(message: Message, options?: PrintOptions): void;
|
|
|
80
89
|
*
|
|
81
90
|
* @param message The structured error message to print.
|
|
82
91
|
* @param options Optional formatting options and exit code.
|
|
92
|
+
* @throws {TypeError} If initialWidth is not a finite integer.
|
|
93
|
+
* @throws {RangeError} If initialWidth is negative or a theme color is invalid.
|
|
83
94
|
*
|
|
84
95
|
* @example
|
|
85
96
|
* ```typescript
|
package/dist/print.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
|
-
import {
|
|
2
|
+
import { getDisplayWidth, renderTerminalTerm, resolveMessageFormatter } from "@optique/core/internal/terminal";
|
|
3
3
|
|
|
4
4
|
//#region src/print.ts
|
|
5
5
|
/**
|
|
@@ -26,30 +26,41 @@ import { formatMessage } from "@optique/core/message";
|
|
|
26
26
|
*
|
|
27
27
|
* @since 0.3.0
|
|
28
28
|
*/
|
|
29
|
-
function print(message
|
|
29
|
+
function print(message, options = {}) {
|
|
30
30
|
const printer = createPrinter({
|
|
31
|
+
...options,
|
|
31
32
|
stream: options.stream ?? "stdout",
|
|
32
33
|
colors: options.colors,
|
|
33
34
|
quotes: options.quotes,
|
|
34
35
|
maxWidth: options.maxWidth
|
|
35
36
|
});
|
|
36
|
-
printer(message
|
|
37
|
+
printer(message);
|
|
37
38
|
}
|
|
38
|
-
function printError(message
|
|
39
|
+
function printError(message, options = {}) {
|
|
39
40
|
const stream = options.stream ?? "stderr";
|
|
40
41
|
const output = process[stream];
|
|
41
42
|
const quotes = options.quotes ?? !output.isTTY;
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const colors = options.colors ?? output.isTTY;
|
|
44
|
+
const useColors = typeof colors === "object" ? true : colors;
|
|
45
|
+
const maxWidth = options.maxWidth ?? output.columns;
|
|
46
|
+
const occupied = options.initialWidth ?? 0;
|
|
47
|
+
if (!Number.isFinite(occupied) || !Number.isInteger(occupied)) throw new TypeError("Initial width must be a finite integer.");
|
|
48
|
+
if (occupied < 0) throw new RangeError("Initial width must be nonnegative.");
|
|
49
|
+
let prefix = renderTerminalTerm({
|
|
50
|
+
type: "errorLabel",
|
|
51
|
+
label: "Error:"
|
|
52
|
+
}, options.theme, useColors) + " ";
|
|
53
|
+
if (maxWidth != null && occupied > 0 && occupied + getDisplayWidth(prefix.split("\n")[0]) > maxWidth) prefix = "\n" + prefix;
|
|
54
|
+
const prefixLines = prefix.split("\n");
|
|
55
|
+
const initialWidth = getDisplayWidth(prefixLines.at(-1) ?? "") + (prefixLines.length === 1 ? options.initialWidth ?? 0 : 0);
|
|
56
|
+
const formatMessage = resolveMessageFormatter(options);
|
|
57
|
+
const formatted = formatMessage(message, {
|
|
58
|
+
colors,
|
|
45
59
|
quotes,
|
|
46
|
-
maxWidth
|
|
60
|
+
maxWidth,
|
|
61
|
+
initialWidth
|
|
47
62
|
});
|
|
48
|
-
|
|
49
|
-
type: "text",
|
|
50
|
-
text: "Error: "
|
|
51
|
-
}, ...message$1];
|
|
52
|
-
printer(errorMessage);
|
|
63
|
+
output.write(prefix + formatted + "\n");
|
|
53
64
|
if (options.exitCode != null) process.exit(options.exitCode);
|
|
54
65
|
}
|
|
55
66
|
/**
|
|
@@ -82,13 +93,15 @@ function printError(message$1, options = {}) {
|
|
|
82
93
|
function createPrinter(options = {}) {
|
|
83
94
|
const stream = options.stream ?? "stdout";
|
|
84
95
|
const output = process[stream];
|
|
96
|
+
const formatMessage = resolveMessageFormatter(options);
|
|
85
97
|
const formatOptions = {
|
|
98
|
+
initialWidth: options.initialWidth,
|
|
86
99
|
colors: options.colors ?? output.isTTY,
|
|
87
100
|
quotes: options.quotes,
|
|
88
101
|
maxWidth: options.maxWidth ?? output.columns
|
|
89
102
|
};
|
|
90
|
-
return (message
|
|
91
|
-
const formatted = formatMessage(message
|
|
103
|
+
return (message) => {
|
|
104
|
+
const formatted = formatMessage(message, formatOptions);
|
|
92
105
|
if (stream === "stderr") process.stderr.write(formatted + "\n");
|
|
93
106
|
else process.stdout.write(formatted + "\n");
|
|
94
107
|
};
|
package/dist/run.cjs
CHANGED
package/dist/run.d.cts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { Message, MessageFormatter } from "@optique/core/message";
|
|
2
|
+
import { TerminalTheme } from "@optique/core/terminal";
|
|
1
3
|
import { ShellCompletion } from "@optique/core/completion";
|
|
2
4
|
import { SourceContext } from "@optique/core/context";
|
|
3
5
|
import { CommandListMode, CommandSubConfig, ContextOptionsParam, OptionSubConfig } from "@optique/core/facade";
|
|
4
6
|
import { InferMode, InferValue, Mode, ModeValue, Parser } from "@optique/core/parser";
|
|
5
7
|
import { Program } from "@optique/core/program";
|
|
6
8
|
import { DocSection, ShowChoicesOptions, ShowDefaultOptions } from "@optique/core/doc";
|
|
7
|
-
import { Message } from "@optique/core/message";
|
|
8
9
|
import { Usage } from "@optique/core/usage";
|
|
9
10
|
|
|
10
11
|
//#region src/run.d.ts
|
|
@@ -13,6 +14,10 @@ import { Usage } from "@optique/core/usage";
|
|
|
13
14
|
* Configuration options for the {@link run} function.
|
|
14
15
|
*/
|
|
15
16
|
interface RunOptions {
|
|
17
|
+
/** Custom message renderer, taking precedence over theme for messages. @since 1.3.0 */
|
|
18
|
+
readonly messageFormatter?: MessageFormatter;
|
|
19
|
+
/** Semantic terminal theme. @since 1.3.0 */
|
|
20
|
+
readonly theme?: TerminalTheme;
|
|
16
21
|
/**
|
|
17
22
|
* The name of the program to display in usage and help messages.
|
|
18
23
|
*
|
package/dist/run.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CommandListMode, CommandSubConfig, ContextOptionsParam, OptionSubConfig } from "@optique/core/facade";
|
|
2
|
-
import { Message } from "@optique/core/message";
|
|
2
|
+
import { Message, MessageFormatter } from "@optique/core/message";
|
|
3
|
+
import { TerminalTheme } from "@optique/core/terminal";
|
|
3
4
|
import { ShellCompletion } from "@optique/core/completion";
|
|
4
5
|
import { SourceContext } from "@optique/core/context";
|
|
5
6
|
import { InferMode, InferValue, Mode, ModeValue, Parser } from "@optique/core/parser";
|
|
@@ -13,6 +14,10 @@ import { Usage } from "@optique/core/usage";
|
|
|
13
14
|
* Configuration options for the {@link run} function.
|
|
14
15
|
*/
|
|
15
16
|
interface RunOptions {
|
|
17
|
+
/** Custom message renderer, taking precedence over theme for messages. @since 1.3.0 */
|
|
18
|
+
readonly messageFormatter?: MessageFormatter;
|
|
19
|
+
/** Semantic terminal theme. @since 1.3.0 */
|
|
20
|
+
readonly theme?: TerminalTheme;
|
|
16
21
|
/**
|
|
17
22
|
* The name of the program to display in usage and help messages.
|
|
18
23
|
*
|
package/dist/run.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/run",
|
|
3
|
-
"version": "1.3.0-dev.
|
|
3
|
+
"version": "1.3.0-dev.2530",
|
|
4
4
|
"description": "Type-safe combinatorial command-line interface parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -76,11 +76,11 @@
|
|
|
76
76
|
},
|
|
77
77
|
"sideEffects": false,
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@optique/core": "1.3.0-dev.
|
|
79
|
+
"@optique/core": "1.3.0-dev.2530+970f0e16"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@optique/config": "1.3.0-dev.
|
|
83
|
-
"@optique/env": "1.3.0-dev.
|
|
82
|
+
"@optique/config": "1.3.0-dev.2530+970f0e16",
|
|
83
|
+
"@optique/env": "1.3.0-dev.2530+970f0e16",
|
|
84
84
|
"@types/node": "^24.0.0",
|
|
85
85
|
"fast-check": "^4.7.0",
|
|
86
86
|
"tsdown": "^0.13.0",
|