@optique/run 0.9.0-dev.211 → 0.9.0-dev.215

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/index.cjs CHANGED
@@ -6,4 +6,6 @@ exports.createPrinter = require_print.createPrinter;
6
6
  exports.path = require_valueparser.path;
7
7
  exports.print = require_print.print;
8
8
  exports.printError = require_print.printError;
9
- exports.run = require_run.run;
9
+ exports.run = require_run.run;
10
+ exports.runAsync = require_run.runAsync;
11
+ exports.runSync = require_run.runSync;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { RunOptions, run } from "./run.cjs";
1
+ import { RunOptions, run, runAsync, runSync } from "./run.cjs";
2
2
  import { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, path } from "./valueparser.cjs";
3
3
  import { PrintErrorOptions, PrintOptions, Printer, PrinterOptions, createPrinter, print, printError } from "./print.cjs";
4
- export { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, PrintErrorOptions, PrintOptions, Printer, PrinterOptions, RunOptions, createPrinter, path, print, printError, run };
4
+ export { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, PrintErrorOptions, PrintOptions, Printer, PrinterOptions, RunOptions, createPrinter, path, print, printError, run, runAsync, runSync };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RunOptions, run } from "./run.js";
1
+ import { RunOptions, run, runAsync, runSync } from "./run.js";
2
2
  import { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, path } from "./valueparser.js";
3
3
  import { PrintErrorOptions, PrintOptions, Printer, PrinterOptions, createPrinter, print, printError } from "./print.js";
4
- export { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, PrintErrorOptions, PrintOptions, Printer, PrinterOptions, RunOptions, createPrinter, path, print, printError, run };
4
+ export { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, PrintErrorOptions, PrintOptions, Printer, PrinterOptions, RunOptions, createPrinter, path, print, printError, run, runAsync, runSync };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { run } from "./run.js";
1
+ import { run, runAsync, runSync } from "./run.js";
2
2
  import { path } from "./valueparser.js";
3
3
  import { createPrinter, print, printError } from "./print.js";
4
4
 
5
- export { createPrinter, path, print, printError, run };
5
+ export { createPrinter, path, print, printError, run, runAsync, runSync };
package/dist/run.cjs CHANGED
@@ -4,70 +4,43 @@ 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(parser, options = {}) {
8
+ return runImpl(parser, options);
9
+ }
7
10
  /**
8
- * Runs a command-line parser with automatic process integration.
11
+ * Runs a synchronous command-line parser with automatic process integration.
9
12
  *
10
- * This function provides a convenient high-level interface for parsing
11
- * command-line arguments in Node.js, Bun, and Deno environments. It
12
- * automatically handles `process.argv`, `process.exit()`, and terminal
13
- * output formatting, eliminating the need to manually pass these values
14
- * as the lower-level `run()` function (from `@optique/core/facade`) requires.
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.
15
16
  *
16
- * The function will automatically:
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);
25
+ }
26
+ /**
27
+ * Runs an asynchronous command-line parser with automatic process integration.
17
28
  *
18
- * - Extract arguments from `process.argv`
19
- * - Detect terminal capabilities for colors and width
20
- * - Exit the process with appropriate codes on help or error
21
- * - Format output according to terminal capabilities
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.
22
32
  *
23
33
  * @template T The parser type being executed.
24
34
  * @param parser The command-line parser to execute.
25
35
  * @param options Configuration options for customizing behavior.
26
- * See {@link RunOptions} for available settings.
27
- * @returns The parsed result if successful. On help display or parse errors,
28
- * the function will call `process.exit()` and not return.
29
- *
30
- * @example
31
- * ```typescript
32
- * import { object, option, run } from "@optique/run";
33
- * import { string, integer } from "@optique/core/valueparser";
34
- *
35
- * const parser = object({
36
- * name: option("-n", "--name", string()),
37
- * port: option("-p", "--port", integer()),
38
- * });
39
- *
40
- * // Automatically uses process.argv, handles errors/help, exits on completion
41
- * const config = run(parser);
42
- * console.log(`Starting server ${config.name} on port ${config.port}`);
43
- * ```
44
- *
45
- * @example
46
- * ```typescript
47
- * // With custom options
48
- * const result = run(parser, {
49
- * programName: "myapp",
50
- * help: "both", // Enable both --help option and help command
51
- * completion: "both", // Enable both completion command and --completion option
52
- * colors: true, // Force colored output
53
- * errorExitCode: 2, // Exit with code 2 on errors
54
- * });
55
- * ```
56
- *
57
- * @example
58
- * ```typescript
59
- * // Shell completion usage
60
- * const result = run(parser, {
61
- * completion: "both",
62
- * });
63
- *
64
- * // Users can then:
65
- * // myapp completion bash > ~/.bash_completion.d/myapp # Generate script
66
- * // source ~/.bash_completion.d/myapp # Enable completion
67
- * // myapp --format=<TAB> # Use completion
68
- * ```
36
+ * @returns A Promise of the parsed result if successful.
37
+ * @since 0.9.0
69
38
  */
70
- function run(parser, options = {}) {
39
+ function runAsync(parser, options = {}) {
40
+ const result = runImpl(parser, options);
41
+ return Promise.resolve(result);
42
+ }
43
+ function runImpl(parser, options = {}) {
71
44
  const { programName = 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, description, footer } = options;
72
45
  const helpConfig = help ? {
73
46
  mode: help,
@@ -108,4 +81,6 @@ function run(parser, options = {}) {
108
81
  }
109
82
 
110
83
  //#endregion
111
- exports.run = run;
84
+ exports.run = run;
85
+ exports.runAsync = runAsync;
86
+ exports.runSync = runSync;
package/dist/run.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ShellCompletion } from "@optique/core/completion";
2
- import { InferValue, Parser } from "@optique/core/parser";
2
+ import { InferMode, InferValue, Mode, ModeValue, Parser } from "@optique/core/parser";
3
3
  import { ShowDefaultOptions } from "@optique/core/doc";
4
4
  import { Message } from "@optique/core/message";
5
5
 
@@ -187,6 +187,36 @@ interface RunOptions {
187
187
  * // myapp --format=<TAB> # Use completion
188
188
  * ```
189
189
  */
190
- declare function run<T extends Parser<unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
190
+ declare function run<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
191
+ declare function run<T extends Parser<"async", unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
192
+ declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): ModeValue<InferMode<T>, InferValue<T>>;
193
+ /**
194
+ * Runs a synchronous command-line parser with automatic process integration.
195
+ *
196
+ * This is a type-safe version of {@link run} that only accepts sync parsers.
197
+ * Use this when you know your parser is sync-only to get direct return values
198
+ * without Promise wrappers.
199
+ *
200
+ * @template T The sync parser type being executed.
201
+ * @param parser The synchronous command-line parser to execute.
202
+ * @param options Configuration options for customizing behavior.
203
+ * @returns The parsed result if successful.
204
+ * @since 0.9.0
205
+ */
206
+ declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
207
+ /**
208
+ * Runs an asynchronous command-line parser with automatic process integration.
209
+ *
210
+ * This function accepts any parser (sync or async) and always returns a
211
+ * Promise. Use this when working with parsers that may contain async
212
+ * value parsers.
213
+ *
214
+ * @template T The parser type being executed.
215
+ * @param parser The command-line parser to execute.
216
+ * @param options Configuration options for customizing behavior.
217
+ * @returns A Promise of the parsed result if successful.
218
+ * @since 0.9.0
219
+ */
220
+ declare function runAsync<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
191
221
  //#endregion
192
- export { RunOptions, run };
222
+ export { RunOptions, run, runAsync, runSync };
package/dist/run.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Message } from "@optique/core/message";
2
2
  import { ShellCompletion } from "@optique/core/completion";
3
- import { InferValue, Parser } from "@optique/core/parser";
3
+ import { InferMode, InferValue, Mode, ModeValue, Parser } from "@optique/core/parser";
4
4
  import { ShowDefaultOptions } from "@optique/core/doc";
5
5
 
6
6
  //#region src/run.d.ts
@@ -187,6 +187,36 @@ interface RunOptions {
187
187
  * // myapp --format=<TAB> # Use completion
188
188
  * ```
189
189
  */
190
- declare function run<T extends Parser<unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
190
+ declare function run<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
191
+ declare function run<T extends Parser<"async", unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
192
+ declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): ModeValue<InferMode<T>, InferValue<T>>;
193
+ /**
194
+ * Runs a synchronous command-line parser with automatic process integration.
195
+ *
196
+ * This is a type-safe version of {@link run} that only accepts sync parsers.
197
+ * Use this when you know your parser is sync-only to get direct return values
198
+ * without Promise wrappers.
199
+ *
200
+ * @template T The sync parser type being executed.
201
+ * @param parser The synchronous command-line parser to execute.
202
+ * @param options Configuration options for customizing behavior.
203
+ * @returns The parsed result if successful.
204
+ * @since 0.9.0
205
+ */
206
+ declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
207
+ /**
208
+ * Runs an asynchronous command-line parser with automatic process integration.
209
+ *
210
+ * This function accepts any parser (sync or async) and always returns a
211
+ * Promise. Use this when working with parsers that may contain async
212
+ * value parsers.
213
+ *
214
+ * @template T The parser type being executed.
215
+ * @param parser The command-line parser to execute.
216
+ * @param options Configuration options for customizing behavior.
217
+ * @returns A Promise of the parsed result if successful.
218
+ * @since 0.9.0
219
+ */
220
+ declare function runAsync<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
191
221
  //#endregion
192
- export { RunOptions, run };
222
+ export { RunOptions, run, runAsync, runSync };
package/dist/run.js CHANGED
@@ -3,70 +3,43 @@ import path from "node:path";
3
3
  import process from "node:process";
4
4
 
5
5
  //#region src/run.ts
6
+ function run(parser, options = {}) {
7
+ return runImpl(parser, options);
8
+ }
6
9
  /**
7
- * Runs a command-line parser with automatic process integration.
10
+ * Runs a synchronous command-line parser with automatic process integration.
8
11
  *
9
- * This function provides a convenient high-level interface for parsing
10
- * command-line arguments in Node.js, Bun, and Deno environments. It
11
- * automatically handles `process.argv`, `process.exit()`, and terminal
12
- * output formatting, eliminating the need to manually pass these values
13
- * as the lower-level `run()` function (from `@optique/core/facade`) requires.
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.
14
15
  *
15
- * The function will automatically:
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);
24
+ }
25
+ /**
26
+ * Runs an asynchronous command-line parser with automatic process integration.
16
27
  *
17
- * - Extract arguments from `process.argv`
18
- * - Detect terminal capabilities for colors and width
19
- * - Exit the process with appropriate codes on help or error
20
- * - Format output according to terminal capabilities
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.
21
31
  *
22
32
  * @template T The parser type being executed.
23
33
  * @param parser The command-line parser to execute.
24
34
  * @param options Configuration options for customizing behavior.
25
- * See {@link RunOptions} for available settings.
26
- * @returns The parsed result if successful. On help display or parse errors,
27
- * the function will call `process.exit()` and not return.
28
- *
29
- * @example
30
- * ```typescript
31
- * import { object, option, run } from "@optique/run";
32
- * import { string, integer } from "@optique/core/valueparser";
33
- *
34
- * const parser = object({
35
- * name: option("-n", "--name", string()),
36
- * port: option("-p", "--port", integer()),
37
- * });
38
- *
39
- * // Automatically uses process.argv, handles errors/help, exits on completion
40
- * const config = run(parser);
41
- * console.log(`Starting server ${config.name} on port ${config.port}`);
42
- * ```
43
- *
44
- * @example
45
- * ```typescript
46
- * // With custom options
47
- * const result = run(parser, {
48
- * programName: "myapp",
49
- * help: "both", // Enable both --help option and help command
50
- * completion: "both", // Enable both completion command and --completion option
51
- * colors: true, // Force colored output
52
- * errorExitCode: 2, // Exit with code 2 on errors
53
- * });
54
- * ```
55
- *
56
- * @example
57
- * ```typescript
58
- * // Shell completion usage
59
- * const result = run(parser, {
60
- * completion: "both",
61
- * });
62
- *
63
- * // Users can then:
64
- * // myapp completion bash > ~/.bash_completion.d/myapp # Generate script
65
- * // source ~/.bash_completion.d/myapp # Enable completion
66
- * // myapp --format=<TAB> # Use completion
67
- * ```
35
+ * @returns A Promise of the parsed result if successful.
36
+ * @since 0.9.0
68
37
  */
69
- function run(parser, options = {}) {
38
+ function runAsync(parser, options = {}) {
39
+ const result = runImpl(parser, options);
40
+ return Promise.resolve(result);
41
+ }
42
+ function runImpl(parser, options = {}) {
70
43
  const { programName = 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, description, footer } = options;
71
44
  const helpConfig = help ? {
72
45
  mode: help,
@@ -107,4 +80,4 @@ function run(parser, options = {}) {
107
80
  }
108
81
 
109
82
  //#endregion
110
- export { run };
83
+ export { run, runAsync, runSync };
@@ -46,6 +46,7 @@ function path(options = {}) {
46
46
  const mustExist = "mustExist" in options ? options.mustExist : false;
47
47
  const mustNotExist = "mustNotExist" in options ? options.mustNotExist : false;
48
48
  return {
49
+ $mode: "sync",
49
50
  metavar,
50
51
  parse(input) {
51
52
  if (extensions && extensions.length > 0) {
@@ -169,6 +169,6 @@ type PathOptions = PathOptionsMustExist | PathOptionsMustNotExist | PathOptionsN
169
169
  * }));
170
170
  * ```
171
171
  */
172
- declare function path(options?: PathOptions): ValueParser<string>;
172
+ declare function path(options?: PathOptions): ValueParser<"sync", string>;
173
173
  //#endregion
174
174
  export { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, path };
@@ -169,6 +169,6 @@ type PathOptions = PathOptionsMustExist | PathOptionsMustNotExist | PathOptionsN
169
169
  * }));
170
170
  * ```
171
171
  */
172
- declare function path(options?: PathOptions): ValueParser<string>;
172
+ declare function path(options?: PathOptions): ValueParser<"sync", string>;
173
173
  //#endregion
174
174
  export { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, path };
@@ -45,6 +45,7 @@ function path(options = {}) {
45
45
  const mustExist = "mustExist" in options ? options.mustExist : false;
46
46
  const mustNotExist = "mustNotExist" in options ? options.mustNotExist : false;
47
47
  return {
48
+ $mode: "sync",
48
49
  metavar,
49
50
  parse(input) {
50
51
  if (extensions && extensions.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/run",
3
- "version": "0.9.0-dev.211+322b48ee",
3
+ "version": "0.9.0-dev.215+13b302c0",
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.9.0-dev.211+322b48ee"
73
+ "@optique/core": "0.9.0-dev.215+13b302c0"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@types/node": "^20.19.9",