@optique/run 0.10.0-dev.323 → 0.10.0-dev.327

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 CHANGED
@@ -4,44 +4,32 @@ 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);
7
+ function run(parserOrProgram, options = {}) {
8
+ return runImpl(parserOrProgram, options);
9
9
  }
10
- /**
11
- * Runs a synchronous command-line parser with automatic process integration.
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
- * Runs an asynchronous command-line parser with automatic process integration.
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(parser, options = {}) {
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;
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
+ footer: program.metadata.footer
30
+ };
31
+ } else parser = parserOrProgram;
32
+ 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, footer = programMetadata?.footer } = options;
45
33
  const helpConfig = help ? {
46
34
  mode: help,
47
35
  onShow: () => node_process.default.exit(0)
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
 
@@ -186,7 +187,11 @@ interface RunOptions {
186
187
  * // source ~/.bash_completion.d/myapp # Enable completion
187
188
  * // myapp --format=<TAB> # Use completion
188
189
  * ```
190
+ *
191
+ * @since 0.11.0 Added support for {@link Program} objects.
189
192
  */
193
+ declare function run<T>(program: Program<"sync", T>, options?: RunOptions): T;
194
+ declare function run<T>(program: Program<"async", T>, options?: RunOptions): Promise<T>;
190
195
  declare function run<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
191
196
  declare function run<T extends Parser<"async", unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
192
197
  declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): ModeValue<InferMode<T>, InferValue<T>>;
@@ -203,6 +208,7 @@ declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, option
203
208
  * @returns The parsed result if successful.
204
209
  * @since 0.9.0
205
210
  */
211
+ declare function runSync<T>(program: Program<"sync", T>, options?: RunOptions): T;
206
212
  declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
207
213
  /**
208
214
  * Runs an asynchronous command-line parser with automatic process integration.
@@ -217,6 +223,8 @@ declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T,
217
223
  * @returns A Promise of the parsed result if successful.
218
224
  * @since 0.9.0
219
225
  */
226
+ declare function runAsync<T>(program: Program<"sync", T>, options?: RunOptions): Promise<T>;
227
+ declare function runAsync<T>(program: Program<"async", T>, options?: RunOptions): Promise<T>;
220
228
  declare function runAsync<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
221
229
  //#endregion
222
230
  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
@@ -186,7 +187,11 @@ interface RunOptions {
186
187
  * // source ~/.bash_completion.d/myapp # Enable completion
187
188
  * // myapp --format=<TAB> # Use completion
188
189
  * ```
190
+ *
191
+ * @since 0.11.0 Added support for {@link Program} objects.
189
192
  */
193
+ declare function run<T>(program: Program<"sync", T>, options?: RunOptions): T;
194
+ declare function run<T>(program: Program<"async", T>, options?: RunOptions): Promise<T>;
190
195
  declare function run<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
191
196
  declare function run<T extends Parser<"async", unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
192
197
  declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): ModeValue<InferMode<T>, InferValue<T>>;
@@ -203,6 +208,7 @@ declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, option
203
208
  * @returns The parsed result if successful.
204
209
  * @since 0.9.0
205
210
  */
211
+ declare function runSync<T>(program: Program<"sync", T>, options?: RunOptions): T;
206
212
  declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
207
213
  /**
208
214
  * Runs an asynchronous command-line parser with automatic process integration.
@@ -217,6 +223,8 @@ declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T,
217
223
  * @returns A Promise of the parsed result if successful.
218
224
  * @since 0.9.0
219
225
  */
226
+ declare function runAsync<T>(program: Program<"sync", T>, options?: RunOptions): Promise<T>;
227
+ declare function runAsync<T>(program: Program<"async", T>, options?: RunOptions): Promise<T>;
220
228
  declare function runAsync<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
221
229
  //#endregion
222
230
  export { RunOptions, run, runAsync, runSync };
package/dist/run.js CHANGED
@@ -3,44 +3,32 @@ 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);
6
+ function run(parserOrProgram, options = {}) {
7
+ return runImpl(parserOrProgram, options);
8
8
  }
9
- /**
10
- * Runs a synchronous command-line parser with automatic process integration.
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
- * Runs an asynchronous command-line parser with automatic process integration.
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(parser, options = {}) {
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;
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
+ footer: program.metadata.footer
29
+ };
30
+ } else parser = parserOrProgram;
31
+ 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, footer = programMetadata?.footer } = options;
44
32
  const helpConfig = help ? {
45
33
  mode: help,
46
34
  onShow: () => process.exit(0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/run",
3
- "version": "0.10.0-dev.323+8b4662d5",
3
+ "version": "0.10.0-dev.327+76d21ea0",
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.323+8b4662d5"
73
+ "@optique/core": "0.10.0-dev.327+76d21ea0"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@types/node": "^20.19.9",