@optique/run 0.10.0-dev.324 → 0.10.0-dev.328
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/run.cjs +28 -34
- package/dist/run.d.cts +26 -0
- package/dist/run.d.ts +26 -0
- package/dist/run.js +28 -34
- package/package.json +2 -2
package/dist/run.cjs
CHANGED
|
@@ -4,44 +4,35 @@ const node_path = require_rolldown_runtime.__toESM(require("node:path"));
|
|
|
4
4
|
const node_process = require_rolldown_runtime.__toESM(require("node:process"));
|
|
5
5
|
|
|
6
6
|
//#region src/run.ts
|
|
7
|
-
function run(
|
|
8
|
-
return runImpl(
|
|
7
|
+
function run(parserOrProgram, options = {}) {
|
|
8
|
+
return runImpl(parserOrProgram, options);
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* This is a type-safe version of {@link run} that only accepts sync parsers.
|
|
14
|
-
* Use this when you know your parser is sync-only to get direct return values
|
|
15
|
-
* without Promise wrappers.
|
|
16
|
-
*
|
|
17
|
-
* @template T The sync parser type being executed.
|
|
18
|
-
* @param parser The synchronous command-line parser to execute.
|
|
19
|
-
* @param options Configuration options for customizing behavior.
|
|
20
|
-
* @returns The parsed result if successful.
|
|
21
|
-
* @since 0.9.0
|
|
22
|
-
*/
|
|
23
|
-
function runSync(parser, options = {}) {
|
|
24
|
-
return runImpl(parser, options);
|
|
10
|
+
function runSync(parserOrProgram, options = {}) {
|
|
11
|
+
return runImpl(parserOrProgram, options);
|
|
25
12
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
* This function accepts any parser (sync or async) and always returns a
|
|
30
|
-
* Promise. Use this when working with parsers that may contain async
|
|
31
|
-
* value parsers.
|
|
32
|
-
*
|
|
33
|
-
* @template T The parser type being executed.
|
|
34
|
-
* @param parser The command-line parser to execute.
|
|
35
|
-
* @param options Configuration options for customizing behavior.
|
|
36
|
-
* @returns A Promise of the parsed result if successful.
|
|
37
|
-
* @since 0.9.0
|
|
38
|
-
*/
|
|
39
|
-
function runAsync(parser, options = {}) {
|
|
40
|
-
const result = runImpl(parser, options);
|
|
13
|
+
function runAsync(parserOrProgram, options = {}) {
|
|
14
|
+
const result = runImpl(parserOrProgram, options);
|
|
41
15
|
return Promise.resolve(result);
|
|
42
16
|
}
|
|
43
|
-
function runImpl(
|
|
44
|
-
const
|
|
17
|
+
function runImpl(parserOrProgram, options = {}) {
|
|
18
|
+
const isProgram = "parser" in parserOrProgram && "metadata" in parserOrProgram;
|
|
19
|
+
let parser;
|
|
20
|
+
let programNameFromProgram;
|
|
21
|
+
let programMetadata;
|
|
22
|
+
if (isProgram) {
|
|
23
|
+
const program = parserOrProgram;
|
|
24
|
+
parser = program.parser;
|
|
25
|
+
programNameFromProgram = program.metadata.name;
|
|
26
|
+
programMetadata = {
|
|
27
|
+
brief: program.metadata.brief,
|
|
28
|
+
description: program.metadata.description,
|
|
29
|
+
examples: program.metadata.examples,
|
|
30
|
+
author: program.metadata.author,
|
|
31
|
+
bugs: program.metadata.bugs,
|
|
32
|
+
footer: program.metadata.footer
|
|
33
|
+
};
|
|
34
|
+
} else parser = parserOrProgram;
|
|
35
|
+
const { programName = programNameFromProgram ?? node_path.default.basename(node_process.default.argv[1] || "cli"), args = node_process.default.argv.slice(2), colors = node_process.default.stdout.isTTY, maxWidth = node_process.default.stdout.columns, showDefault, help, version, completion, aboveError = "usage", errorExitCode = 1, brief = programMetadata?.brief, description = programMetadata?.description, examples = programMetadata?.examples, author = programMetadata?.author, bugs = programMetadata?.bugs, footer = programMetadata?.footer } = options;
|
|
45
36
|
const helpConfig = help ? {
|
|
46
37
|
mode: help,
|
|
47
38
|
onShow: () => node_process.default.exit(0)
|
|
@@ -73,6 +64,9 @@ function runImpl(parser, options = {}) {
|
|
|
73
64
|
aboveError,
|
|
74
65
|
brief,
|
|
75
66
|
description,
|
|
67
|
+
examples,
|
|
68
|
+
author,
|
|
69
|
+
bugs,
|
|
76
70
|
footer,
|
|
77
71
|
onError() {
|
|
78
72
|
return node_process.default.exit(errorExitCode);
|
package/dist/run.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ShellCompletion } from "@optique/core/completion";
|
|
2
2
|
import { InferMode, InferValue, Mode, ModeValue, Parser } from "@optique/core/parser";
|
|
3
|
+
import { Program } from "@optique/core/program";
|
|
3
4
|
import { ShowDefaultOptions } from "@optique/core/doc";
|
|
4
5
|
import { Message } from "@optique/core/message";
|
|
5
6
|
|
|
@@ -117,6 +118,24 @@ interface RunOptions {
|
|
|
117
118
|
* @since 0.4.0
|
|
118
119
|
*/
|
|
119
120
|
readonly description?: Message;
|
|
121
|
+
/**
|
|
122
|
+
* Usage examples for the program.
|
|
123
|
+
*
|
|
124
|
+
* @since 0.10.0
|
|
125
|
+
*/
|
|
126
|
+
readonly examples?: Message;
|
|
127
|
+
/**
|
|
128
|
+
* Author information.
|
|
129
|
+
*
|
|
130
|
+
* @since 0.10.0
|
|
131
|
+
*/
|
|
132
|
+
readonly author?: Message;
|
|
133
|
+
/**
|
|
134
|
+
* Information about where to report bugs.
|
|
135
|
+
*
|
|
136
|
+
* @since 0.10.0
|
|
137
|
+
*/
|
|
138
|
+
readonly bugs?: Message;
|
|
120
139
|
/**
|
|
121
140
|
* Footer text shown at the bottom of help text.
|
|
122
141
|
*
|
|
@@ -186,7 +205,11 @@ interface RunOptions {
|
|
|
186
205
|
* // source ~/.bash_completion.d/myapp # Enable completion
|
|
187
206
|
* // myapp --format=<TAB> # Use completion
|
|
188
207
|
* ```
|
|
208
|
+
*
|
|
209
|
+
* @since 0.11.0 Added support for {@link Program} objects.
|
|
189
210
|
*/
|
|
211
|
+
declare function run<T>(program: Program<"sync", T>, options?: RunOptions): T;
|
|
212
|
+
declare function run<T>(program: Program<"async", T>, options?: RunOptions): Promise<T>;
|
|
190
213
|
declare function run<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
|
|
191
214
|
declare function run<T extends Parser<"async", unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
|
|
192
215
|
declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): ModeValue<InferMode<T>, InferValue<T>>;
|
|
@@ -203,6 +226,7 @@ declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, option
|
|
|
203
226
|
* @returns The parsed result if successful.
|
|
204
227
|
* @since 0.9.0
|
|
205
228
|
*/
|
|
229
|
+
declare function runSync<T>(program: Program<"sync", T>, options?: RunOptions): T;
|
|
206
230
|
declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
|
|
207
231
|
/**
|
|
208
232
|
* Runs an asynchronous command-line parser with automatic process integration.
|
|
@@ -217,6 +241,8 @@ declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T,
|
|
|
217
241
|
* @returns A Promise of the parsed result if successful.
|
|
218
242
|
* @since 0.9.0
|
|
219
243
|
*/
|
|
244
|
+
declare function runAsync<T>(program: Program<"sync", T>, options?: RunOptions): Promise<T>;
|
|
245
|
+
declare function runAsync<T>(program: Program<"async", T>, options?: RunOptions): Promise<T>;
|
|
220
246
|
declare function runAsync<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
|
|
221
247
|
//#endregion
|
|
222
248
|
export { RunOptions, run, runAsync, runSync };
|
package/dist/run.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Message } from "@optique/core/message";
|
|
2
2
|
import { ShellCompletion } from "@optique/core/completion";
|
|
3
3
|
import { InferMode, InferValue, Mode, ModeValue, Parser } from "@optique/core/parser";
|
|
4
|
+
import { Program } from "@optique/core/program";
|
|
4
5
|
import { ShowDefaultOptions } from "@optique/core/doc";
|
|
5
6
|
|
|
6
7
|
//#region src/run.d.ts
|
|
@@ -117,6 +118,24 @@ interface RunOptions {
|
|
|
117
118
|
* @since 0.4.0
|
|
118
119
|
*/
|
|
119
120
|
readonly description?: Message;
|
|
121
|
+
/**
|
|
122
|
+
* Usage examples for the program.
|
|
123
|
+
*
|
|
124
|
+
* @since 0.10.0
|
|
125
|
+
*/
|
|
126
|
+
readonly examples?: Message;
|
|
127
|
+
/**
|
|
128
|
+
* Author information.
|
|
129
|
+
*
|
|
130
|
+
* @since 0.10.0
|
|
131
|
+
*/
|
|
132
|
+
readonly author?: Message;
|
|
133
|
+
/**
|
|
134
|
+
* Information about where to report bugs.
|
|
135
|
+
*
|
|
136
|
+
* @since 0.10.0
|
|
137
|
+
*/
|
|
138
|
+
readonly bugs?: Message;
|
|
120
139
|
/**
|
|
121
140
|
* Footer text shown at the bottom of help text.
|
|
122
141
|
*
|
|
@@ -186,7 +205,11 @@ interface RunOptions {
|
|
|
186
205
|
* // source ~/.bash_completion.d/myapp # Enable completion
|
|
187
206
|
* // myapp --format=<TAB> # Use completion
|
|
188
207
|
* ```
|
|
208
|
+
*
|
|
209
|
+
* @since 0.11.0 Added support for {@link Program} objects.
|
|
189
210
|
*/
|
|
211
|
+
declare function run<T>(program: Program<"sync", T>, options?: RunOptions): T;
|
|
212
|
+
declare function run<T>(program: Program<"async", T>, options?: RunOptions): Promise<T>;
|
|
190
213
|
declare function run<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
|
|
191
214
|
declare function run<T extends Parser<"async", unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
|
|
192
215
|
declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): ModeValue<InferMode<T>, InferValue<T>>;
|
|
@@ -203,6 +226,7 @@ declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, option
|
|
|
203
226
|
* @returns The parsed result if successful.
|
|
204
227
|
* @since 0.9.0
|
|
205
228
|
*/
|
|
229
|
+
declare function runSync<T>(program: Program<"sync", T>, options?: RunOptions): T;
|
|
206
230
|
declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
|
|
207
231
|
/**
|
|
208
232
|
* Runs an asynchronous command-line parser with automatic process integration.
|
|
@@ -217,6 +241,8 @@ declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T,
|
|
|
217
241
|
* @returns A Promise of the parsed result if successful.
|
|
218
242
|
* @since 0.9.0
|
|
219
243
|
*/
|
|
244
|
+
declare function runAsync<T>(program: Program<"sync", T>, options?: RunOptions): Promise<T>;
|
|
245
|
+
declare function runAsync<T>(program: Program<"async", T>, options?: RunOptions): Promise<T>;
|
|
220
246
|
declare function runAsync<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
|
|
221
247
|
//#endregion
|
|
222
248
|
export { RunOptions, run, runAsync, runSync };
|
package/dist/run.js
CHANGED
|
@@ -3,44 +3,35 @@ import path from "node:path";
|
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
|
|
5
5
|
//#region src/run.ts
|
|
6
|
-
function run(
|
|
7
|
-
return runImpl(
|
|
6
|
+
function run(parserOrProgram, options = {}) {
|
|
7
|
+
return runImpl(parserOrProgram, options);
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* This is a type-safe version of {@link run} that only accepts sync parsers.
|
|
13
|
-
* Use this when you know your parser is sync-only to get direct return values
|
|
14
|
-
* without Promise wrappers.
|
|
15
|
-
*
|
|
16
|
-
* @template T The sync parser type being executed.
|
|
17
|
-
* @param parser The synchronous command-line parser to execute.
|
|
18
|
-
* @param options Configuration options for customizing behavior.
|
|
19
|
-
* @returns The parsed result if successful.
|
|
20
|
-
* @since 0.9.0
|
|
21
|
-
*/
|
|
22
|
-
function runSync(parser, options = {}) {
|
|
23
|
-
return runImpl(parser, options);
|
|
9
|
+
function runSync(parserOrProgram, options = {}) {
|
|
10
|
+
return runImpl(parserOrProgram, options);
|
|
24
11
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
* This function accepts any parser (sync or async) and always returns a
|
|
29
|
-
* Promise. Use this when working with parsers that may contain async
|
|
30
|
-
* value parsers.
|
|
31
|
-
*
|
|
32
|
-
* @template T The parser type being executed.
|
|
33
|
-
* @param parser The command-line parser to execute.
|
|
34
|
-
* @param options Configuration options for customizing behavior.
|
|
35
|
-
* @returns A Promise of the parsed result if successful.
|
|
36
|
-
* @since 0.9.0
|
|
37
|
-
*/
|
|
38
|
-
function runAsync(parser, options = {}) {
|
|
39
|
-
const result = runImpl(parser, options);
|
|
12
|
+
function runAsync(parserOrProgram, options = {}) {
|
|
13
|
+
const result = runImpl(parserOrProgram, options);
|
|
40
14
|
return Promise.resolve(result);
|
|
41
15
|
}
|
|
42
|
-
function runImpl(
|
|
43
|
-
const
|
|
16
|
+
function runImpl(parserOrProgram, options = {}) {
|
|
17
|
+
const isProgram = "parser" in parserOrProgram && "metadata" in parserOrProgram;
|
|
18
|
+
let parser;
|
|
19
|
+
let programNameFromProgram;
|
|
20
|
+
let programMetadata;
|
|
21
|
+
if (isProgram) {
|
|
22
|
+
const program = parserOrProgram;
|
|
23
|
+
parser = program.parser;
|
|
24
|
+
programNameFromProgram = program.metadata.name;
|
|
25
|
+
programMetadata = {
|
|
26
|
+
brief: program.metadata.brief,
|
|
27
|
+
description: program.metadata.description,
|
|
28
|
+
examples: program.metadata.examples,
|
|
29
|
+
author: program.metadata.author,
|
|
30
|
+
bugs: program.metadata.bugs,
|
|
31
|
+
footer: program.metadata.footer
|
|
32
|
+
};
|
|
33
|
+
} else parser = parserOrProgram;
|
|
34
|
+
const { programName = programNameFromProgram ?? path.basename(process.argv[1] || "cli"), args = process.argv.slice(2), colors = process.stdout.isTTY, maxWidth = process.stdout.columns, showDefault, help, version, completion, aboveError = "usage", errorExitCode = 1, brief = programMetadata?.brief, description = programMetadata?.description, examples = programMetadata?.examples, author = programMetadata?.author, bugs = programMetadata?.bugs, footer = programMetadata?.footer } = options;
|
|
44
35
|
const helpConfig = help ? {
|
|
45
36
|
mode: help,
|
|
46
37
|
onShow: () => process.exit(0)
|
|
@@ -72,6 +63,9 @@ function runImpl(parser, options = {}) {
|
|
|
72
63
|
aboveError,
|
|
73
64
|
brief,
|
|
74
65
|
description,
|
|
66
|
+
examples,
|
|
67
|
+
author,
|
|
68
|
+
bugs,
|
|
75
69
|
footer,
|
|
76
70
|
onError() {
|
|
77
71
|
return process.exit(errorExitCode);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/run",
|
|
3
|
-
"version": "0.10.0-dev.
|
|
3
|
+
"version": "0.10.0-dev.328+4e5f40d5",
|
|
4
4
|
"description": "Type-safe combinatorial command-line interface parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
"sideEffects": false,
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@optique/core": "0.10.0-dev.
|
|
73
|
+
"@optique/core": "0.10.0-dev.328+4e5f40d5"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/node": "^20.19.9",
|