@optique/run 0.10.7 → 1.0.0-dev.1116

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/README.md CHANGED
@@ -1,9 +1,6 @@
1
1
  @optique/run
2
2
  ============
3
3
 
4
- > [!WARNING]
5
- > The API is stabilizing, but may change before the 1.0 release.
6
-
7
4
  Process-integrated CLI parser for Node.js, Bun, and Deno that provides a
8
5
  batteries-included interface for *@optique/core* with automatic `process.argv`
9
6
  handling, `process.exit()`, and terminal capabilities.
@@ -43,7 +40,8 @@ Quick example
43
40
 
44
41
  ~~~~ typescript
45
42
  import { run } from "@optique/run";
46
- import { object, option, argument } from "@optique/core/parser";
43
+ import { option, argument } from "@optique/core/primitives";
44
+ import { object } from "@optique/core/constructs";
47
45
  import { string, integer } from "@optique/core/valueparser";
48
46
 
49
47
  const parser = object({
@@ -73,13 +71,14 @@ Verbose mode enabled.
73
71
  Shell completion
74
72
  ----------------
75
73
 
76
- *@optique/run* automatically supports shell completion for Bash and zsh.
77
- Enable completion by adding the `completion` option to your `run()`
78
- configuration:
74
+ *@optique/run* automatically supports shell completion for Bash, zsh, fish,
75
+ PowerShell, and Nushell. Enable completion by adding the `completion` option
76
+ to your `run()` configuration:
79
77
 
80
78
  ~~~~ typescript
81
79
  import { run } from "@optique/run";
82
- import { object, option, argument } from "@optique/core/parser";
80
+ import { option, argument } from "@optique/core/primitives";
81
+ import { object } from "@optique/core/constructs";
83
82
  import { string, choice } from "@optique/core/valueparser";
84
83
 
85
84
  const parser = object({
@@ -89,19 +88,30 @@ const parser = object({
89
88
  });
90
89
 
91
90
  const config = run(parser, {
92
- completion: { mode: "both" }
91
+ completion: "both"
93
92
  });
94
93
  ~~~~
95
94
 
96
95
  Users can then generate and install completion scripts:
97
96
 
98
97
  ~~~~ bash
99
- # Generate Bash completion script
98
+ # Bash
100
99
  myapp completion bash > ~/.bashrc.d/myapp.bash
101
100
  source ~/.bashrc.d/myapp.bash
102
101
 
103
- # Generate zsh completion script
102
+ # zsh
104
103
  myapp completion zsh > ~/.zsh/completions/_myapp
104
+
105
+ # fish
106
+ myapp completion fish > ~/.config/fish/completions/myapp.fish
107
+
108
+ # PowerShell
109
+ myapp completion pwsh > myapp-completion.ps1
110
+ . ./myapp-completion.ps1
111
+
112
+ # Nushell
113
+ myapp completion nu | save myapp-completion.nu
114
+ source myapp-completion.nu
105
115
  ~~~~
106
116
 
107
117
  The completion system automatically provides intelligent suggestions for:
package/dist/run.cjs CHANGED
@@ -4,111 +4,153 @@ 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 getProgramHelpMetadata(metadata) {
8
+ return {
9
+ brief: metadata.brief,
10
+ description: metadata.description,
11
+ examples: metadata.examples,
12
+ author: metadata.author,
13
+ bugs: metadata.bugs,
14
+ footer: metadata.footer
15
+ };
16
+ }
17
+ function resolveProgramInput(parserOrProgram, options) {
18
+ if ("parser" in parserOrProgram && "metadata" in parserOrProgram) return {
19
+ parser: parserOrProgram.parser,
20
+ options: options.programName == null ? {
21
+ ...options,
22
+ programName: parserOrProgram.metadata.name
23
+ } : options,
24
+ programMetadata: getProgramHelpMetadata(parserOrProgram.metadata)
25
+ };
26
+ return {
27
+ parser: parserOrProgram,
28
+ options
29
+ };
30
+ }
7
31
  function run(parserOrProgram, options = {}) {
8
32
  return runImpl(parserOrProgram, options);
9
33
  }
10
34
  function runSync(parserOrProgram, options = {}) {
35
+ const contexts = options.contexts;
36
+ if (contexts && contexts.length > 0) {
37
+ const resolved = resolveProgramInput(parserOrProgram, options);
38
+ const { parser, programMetadata } = resolved;
39
+ options = resolved.options;
40
+ const { programName, args, coreOptions } = buildCoreOptions(options, programMetadata);
41
+ const runWithOptions = {
42
+ ...coreOptions,
43
+ contextOptions: options.contextOptions,
44
+ args
45
+ };
46
+ return (0, __optique_core_facade.runWithSync)(parser, programName, contexts, runWithOptions);
47
+ }
11
48
  return runImpl(parserOrProgram, options);
12
49
  }
13
50
  function runAsync(parserOrProgram, options = {}) {
14
51
  const result = runImpl(parserOrProgram, options);
15
52
  return Promise.resolve(result);
16
53
  }
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
54
+ /**
55
+ * Builds core run options from the simplified RunOptions format.
56
+ *
57
+ * Converts the user-friendly RunOptions (string-based help/version/completion)
58
+ * into the verbose CoreRunOptions format expected by `runParser()`, `runWith()`,
59
+ * and `runWithSync()` from `@optique/core/facade`.
60
+ *
61
+ * @internal
62
+ */
63
+ function buildCoreOptions(options, programMetadata) {
64
+ const programName = options.programName ?? node_path.default.basename(node_process.default.argv[1] ?? "cli");
65
+ const args = options.args ?? node_process.default.argv.slice(2);
66
+ const stdout = options.stdout ?? ((line) => {
67
+ node_process.default.stdout.write(`${line}\n`);
68
+ });
69
+ const stderr = options.stderr ?? ((line) => {
70
+ node_process.default.stderr.write(`${line}\n`);
71
+ });
72
+ const onExit = options.onExit ?? ((exitCode) => node_process.default.exit(exitCode));
73
+ const colors = options.colors ?? node_process.default.stdout.isTTY;
74
+ const maxWidth = options.maxWidth ?? node_process.default.stdout.columns;
75
+ const showDefault = options.showDefault;
76
+ const showChoices = options.showChoices;
77
+ const sectionOrder = options.sectionOrder;
78
+ const help = options.help;
79
+ const version = options.version;
80
+ const completion = options.completion;
81
+ const aboveError = options.aboveError ?? "usage";
82
+ const errorExitCode = options.errorExitCode ?? 1;
83
+ const brief = options.brief ?? programMetadata?.brief;
84
+ const description = options.description ?? programMetadata?.description;
85
+ const examples = options.examples ?? programMetadata?.examples;
86
+ const author = options.author ?? programMetadata?.author;
87
+ const bugs = options.bugs ?? programMetadata?.bugs;
88
+ const footer = options.footer ?? programMetadata?.footer;
89
+ const onShow = () => onExit(0);
90
+ const helpConfig = (() => {
91
+ if (!help) return void 0;
92
+ if (typeof help === "string") switch (help) {
93
+ case "command": return {
94
+ command: true,
95
+ onShow
96
+ };
97
+ case "option": return {
98
+ option: true,
99
+ onShow
100
+ };
101
+ case "both": return {
102
+ command: true,
103
+ option: true,
104
+ onShow
105
+ };
106
+ }
107
+ return {
108
+ ...help,
109
+ onShow
33
110
  };
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, showChoices, 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;
36
- const helpConfig = help ? typeof help === "string" ? {
37
- mode: help,
38
- onShow: () => node_process.default.exit(0)
39
- } : {
40
- mode: help.mode,
41
- group: help.group,
42
- onShow: () => node_process.default.exit(0)
43
- } : void 0;
111
+ })();
44
112
  const versionConfig = (() => {
45
113
  if (!version) return void 0;
46
114
  if (typeof version === "string") return {
47
- mode: "option",
48
115
  value: version,
49
- onShow: () => node_process.default.exit(0)
50
- };
51
- const mode = version.mode ?? "option";
52
- if (mode === "command" || mode === "both") return {
53
- mode,
54
- value: version.value,
55
- group: version.group,
56
- onShow: () => node_process.default.exit(0)
116
+ option: true,
117
+ onShow
57
118
  };
58
119
  return {
59
- mode,
60
- value: version.value,
61
- onShow: () => node_process.default.exit(0)
120
+ ...version,
121
+ onShow
62
122
  };
63
123
  })();
64
124
  const completionConfig = (() => {
65
125
  if (!completion) return void 0;
66
- const onShow = () => node_process.default.exit(0);
67
- if (typeof completion === "string") return {
68
- mode: completion,
69
- name: "both",
70
- helpVisibility: "both",
71
- onShow
72
- };
73
- const mode = completion.mode ?? "both";
74
- const shells = completion.shells;
75
- const cGroup = completion.group;
76
- if (completion.name === "singular") return {
77
- mode,
78
- shells,
79
- ...cGroup != null && { group: cGroup },
80
- name: "singular",
81
- helpVisibility: completion.helpVisibility ?? "singular",
82
- onShow
83
- };
84
- if (completion.name === "plural") return {
85
- mode,
86
- shells,
87
- ...cGroup != null && { group: cGroup },
88
- name: "plural",
89
- helpVisibility: completion.helpVisibility ?? "plural",
90
- onShow
91
- };
126
+ if (typeof completion === "string") switch (completion) {
127
+ case "command": return {
128
+ command: true,
129
+ onShow
130
+ };
131
+ case "option": return {
132
+ option: true,
133
+ onShow
134
+ };
135
+ case "both": return {
136
+ command: true,
137
+ option: true,
138
+ onShow
139
+ };
140
+ }
92
141
  return {
93
- mode,
94
- shells,
95
- ...cGroup != null && { group: cGroup },
96
- name: "both",
97
- helpVisibility: completion.helpVisibility ?? "both",
142
+ ...completion,
98
143
  onShow
99
144
  };
100
145
  })();
101
- return (0, __optique_core_facade.runParser)(parser, programName, args, {
102
- stderr(line) {
103
- node_process.default.stderr.write(`${line}\n`);
104
- },
105
- stdout(line) {
106
- node_process.default.stdout.write(`${line}\n`);
107
- },
146
+ const coreOptions = {
147
+ stderr,
148
+ stdout,
108
149
  colors,
109
150
  maxWidth,
110
151
  showDefault,
111
152
  showChoices,
153
+ sectionOrder,
112
154
  help: helpConfig,
113
155
  version: versionConfig,
114
156
  completion: completionConfig,
@@ -120,9 +162,31 @@ function runImpl(parserOrProgram, options = {}) {
120
162
  bugs,
121
163
  footer,
122
164
  onError() {
123
- return node_process.default.exit(errorExitCode);
165
+ return onExit(errorExitCode);
124
166
  }
125
- });
167
+ };
168
+ return {
169
+ programName,
170
+ args,
171
+ coreOptions
172
+ };
173
+ }
174
+ function runImpl(parserOrProgram, options = {}) {
175
+ const resolved = resolveProgramInput(parserOrProgram, options);
176
+ const { parser, programMetadata } = resolved;
177
+ options = resolved.options;
178
+ const contexts = options.contexts;
179
+ if (contexts && contexts.length > 0) {
180
+ const { programName: programName$1, args: args$1, coreOptions: coreOptions$1 } = buildCoreOptions(options, programMetadata);
181
+ const runWithOptions = {
182
+ ...coreOptions$1,
183
+ contextOptions: options.contextOptions,
184
+ args: args$1
185
+ };
186
+ return (0, __optique_core_facade.runWith)(parser, programName$1, contexts, runWithOptions);
187
+ }
188
+ const { programName, args, coreOptions } = buildCoreOptions(options, programMetadata);
189
+ return (0, __optique_core_facade.runParser)(parser, programName, args, coreOptions);
126
190
  }
127
191
 
128
192
  //#endregion
package/dist/run.d.cts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { ShellCompletion } from "@optique/core/completion";
2
+ import { SourceContext } from "@optique/core/context";
3
+ import { CommandSubConfig, ContextOptionsParam, OptionSubConfig } from "@optique/core/facade";
2
4
  import { InferMode, InferValue, Mode, ModeValue, Parser } from "@optique/core/parser";
3
5
  import { Program } from "@optique/core/program";
4
- import { ShowChoicesOptions, ShowDefaultOptions } from "@optique/core/doc";
6
+ import { DocSection, ShowChoicesOptions, ShowDefaultOptions } from "@optique/core/doc";
5
7
  import { Message } from "@optique/core/message";
6
8
 
7
9
  //#region src/run.d.ts
@@ -22,6 +24,26 @@ interface RunOptions {
22
24
  * @default `process.argv.slice(2)` (arguments after the script name)
23
25
  */
24
26
  readonly args?: readonly string[];
27
+ /**
28
+ * Function used to output help and usage messages. Assumes it prints the
29
+ * ending newline.
30
+ *
31
+ * @default Writes to `process.stdout` with a trailing newline
32
+ */
33
+ readonly stdout?: (text: string) => void;
34
+ /**
35
+ * Function used to output error messages. Assumes it prints the ending
36
+ * newline.
37
+ *
38
+ * @default Writes to `process.stderr` with a trailing newline
39
+ */
40
+ readonly stderr?: (text: string) => void;
41
+ /**
42
+ * Function used to exit the process on help/version display or parse error.
43
+ *
44
+ * @default `process.exit`
45
+ */
46
+ readonly onExit?: (exitCode: number) => never;
25
47
  /**
26
48
  * Whether to enable colored output in help and error messages.
27
49
  *
@@ -62,69 +84,86 @@ interface RunOptions {
62
84
  * @since 0.10.0
63
85
  */
64
86
  readonly showChoices?: boolean | ShowChoicesOptions;
87
+ /**
88
+ * A custom comparator function to control the order of sections in the
89
+ * help output. When provided, it is used instead of the default smart
90
+ * sort (command-only sections first, then mixed, then option/argument-only
91
+ * sections). Sections that compare equal (return `0`) preserve their
92
+ * original relative order.
93
+ *
94
+ * @param a The first section to compare.
95
+ * @param b The second section to compare.
96
+ * @returns A negative number if `a` should appear before `b`, a positive
97
+ * number if `a` should appear after `b`, or `0` if they are equal.
98
+ * @since 1.0.0
99
+ */
100
+ readonly sectionOrder?: (a: DocSection, b: DocSection) => number;
65
101
  /**
66
102
  * Help configuration. Determines how help is made available:
67
103
  *
68
104
  * - `"command"`: Only the `help` subcommand is available
69
105
  * - `"option"`: Only the `--help` option is available
70
106
  * - `"both"`: Both `help` subcommand and `--help` option are available
71
- * - `object`: Advanced configuration with mode and group
72
- * - `mode`: "command" | "both"
73
- * - `group`: Group label for help command in help output (optional)
107
+ * - `object`: Advanced configuration with `command` and/or `option`
108
+ * sub-configs. At least one of `command` or `option` must be specified.
74
109
  *
75
110
  * When not provided, help functionality is disabled.
111
+ *
112
+ * @since 1.0.0
76
113
  */
77
- readonly help?: "command" | "option" | "both" | {
78
- readonly mode: "command" | "both";
79
- /**
80
- * Group label for the help command in help output.
81
- * @since 0.10.0
82
- */
83
- readonly group?: string;
84
- };
114
+ readonly help?: "command" | "option" | "both" | (({
115
+ readonly command: true | CommandSubConfig;
116
+ readonly option?: true | OptionSubConfig;
117
+ } | {
118
+ readonly option: true | OptionSubConfig;
119
+ readonly command?: true | CommandSubConfig;
120
+ }));
85
121
  /**
86
122
  * Version configuration. Determines how version is made available:
87
123
  *
88
124
  * - `string`: Version value with default `"option"` mode (--version only)
89
- * - `object`: Advanced configuration with version value and mode
90
- * - `value`: The version string to display
91
- * - `mode`: "command" | "option" | "both" (default: "option")
92
- * - `group`: Group label for version command in help output (only
93
- * when mode is "command" or "both")
125
+ * - `object`: Advanced configuration with version value and `command`
126
+ * and/or `option` sub-configs. At least one of `command` or `option`
127
+ * must be specified.
94
128
  *
95
129
  * When not provided, version functionality is disabled.
130
+ *
131
+ * @since 1.0.0
96
132
  */
97
- readonly version?: string | {
133
+ readonly version?: string | ({
98
134
  readonly value: string;
99
- readonly mode: "command" | "both";
100
- /**
101
- * Group label for the version command in help output.
102
- * @since 0.10.0
103
- */
104
- readonly group?: string;
135
+ } & ({
136
+ readonly command: true | CommandSubConfig;
137
+ readonly option?: true | OptionSubConfig;
105
138
  } | {
106
- readonly value: string;
107
- readonly mode?: "option";
108
- readonly group?: never;
109
- };
139
+ readonly option: true | OptionSubConfig;
140
+ readonly command?: true | CommandSubConfig;
141
+ }));
110
142
  /**
111
- * Completion configuration. Determines how shell completion is made available:
143
+ * Completion configuration. Determines how shell completion is made
144
+ * available:
112
145
  *
113
146
  * - `"command"`: Only the `completion` subcommand is available
114
147
  * - `"option"`: Only the `--completion` option is available
115
- * - `"both"`: Both `completion` subcommand and `--completion` option are available
116
- * - `object`: Advanced configuration with mode and custom shells
117
- * - `mode`: "command" | "option" | "both" (default: "both")
118
- * - `name`: "singular" | "plural" | "both" (default: "both")
119
- * - `helpVisibility`: "singular" | "plural" | "both" | "none"
120
- * (default: matches `name`)
121
- * - `shells`: Custom shell completions (optional)
148
+ * - `"both"`: Both `completion` subcommand and `--completion` option
149
+ * are available
150
+ * - `object`: Advanced configuration with `command` and/or `option`
151
+ * sub-configs and optional custom shells. At least one of `command`
152
+ * or `option` must be specified.
122
153
  *
123
154
  * When not provided, completion functionality is disabled.
124
155
  *
125
- * @since 0.6.0
156
+ * @since 1.0.0
126
157
  */
127
- readonly completion?: "command" | "option" | "both" | CompletionOptions;
158
+ readonly completion?: "command" | "option" | "both" | ({
159
+ readonly shells?: Record<string, ShellCompletion>;
160
+ } & ({
161
+ readonly command: true | CommandSubConfig;
162
+ readonly option?: true | OptionSubConfig;
163
+ } | {
164
+ readonly option: true | OptionSubConfig;
165
+ readonly command?: true | CommandSubConfig;
166
+ }));
128
167
  /**
129
168
  * What to display above error messages:
130
169
  *
@@ -177,49 +216,59 @@ interface RunOptions {
177
216
  * @since 0.4.0
178
217
  */
179
218
  readonly footer?: Message;
180
- }
181
- type CompletionHelpVisibility = "singular" | "plural" | "both" | "none";
182
- type CompletionOptionsBase = {
183
- readonly mode?: "command" | "both";
184
- /**
185
- * Group label for the completion command in help output.
186
- * @since 0.10.0
187
- */
188
- readonly group?: string;
189
- readonly shells?: Record<string, ShellCompletion>;
190
- } | {
191
- readonly mode: "option";
192
- readonly group?: never;
193
- readonly shells?: Record<string, ShellCompletion>;
194
- };
195
- type CompletionOptionsBoth = CompletionOptionsBase & {
196
- readonly name?: "both";
197
- /**
198
- * Controls which completion aliases are shown in help and usage output.
199
- *
200
- * @since 0.10.0
201
- */
202
- readonly helpVisibility?: CompletionHelpVisibility;
203
- };
204
- type CompletionOptionsSingular = CompletionOptionsBase & {
205
- readonly name: "singular";
206
219
  /**
207
- * Controls which completion aliases are shown in help and usage output.
220
+ * Source contexts to use for two-phase parsing. When provided, the
221
+ * runner delegates to `runWith()` (or `runWithSync()` for sync parsers)
222
+ * from `@optique/core/facade`, which handles annotation collection and
223
+ * multi-phase parsing automatically.
208
224
  *
209
- * @since 0.10.0
225
+ * @since 1.0.0
210
226
  */
211
- readonly helpVisibility?: "singular" | "none";
212
- };
213
- type CompletionOptionsPlural = CompletionOptionsBase & {
214
- readonly name: "plural";
227
+ readonly contexts?: readonly SourceContext<unknown>[];
215
228
  /**
216
- * Controls which completion aliases are shown in help and usage output.
229
+ * Options to forward to source contexts. When contexts declare
230
+ * required options (via `$requiredOptions`), pass them here to
231
+ * avoid name collisions with runner-level options such as `help`,
232
+ * `programName`, or `version`.
217
233
  *
218
- * @since 0.10.0
234
+ * @since 1.0.0
219
235
  */
220
- readonly helpVisibility?: "plural" | "none";
221
- };
222
- type CompletionOptions = CompletionOptionsBoth | CompletionOptionsSingular | CompletionOptionsPlural;
236
+ readonly contextOptions?: Record<string, unknown>;
237
+ }
238
+ /**
239
+ * Rejects context tuples that are statically known to be empty so those calls
240
+ * fall back to the no-context overloads.
241
+ */
242
+ type RejectEmptyContexts<TContexts extends readonly SourceContext<unknown>[]> = TContexts extends readonly [] ? never : unknown;
243
+ /**
244
+ * Represents a context tuple that is statically known to contain at least one
245
+ * source context.
246
+ */
247
+ type NonEmptySourceContexts = readonly [SourceContext<unknown>, ...SourceContext<unknown>[]];
248
+ /**
249
+ * Rejects option shapes that may carry a non-empty `contexts` array so plain
250
+ * Program overloads do not bypass the context-aware overloads.
251
+ */
252
+ type ContextsFromOptions<TOptions> = [Exclude<TOptions, undefined>] extends [never] ? undefined : Exclude<TOptions, undefined> extends {
253
+ readonly contexts?: infer TContexts extends readonly SourceContext<unknown>[] | undefined;
254
+ } ? TContexts : undefined;
255
+ type RejectContextfulOptions<TOptions> = [ContextsFromOptions<TOptions>] extends [undefined | readonly []] ? unknown : never;
256
+ /**
257
+ * Rejects option shapes that introduce keys outside the public `RunOptions`
258
+ * contract, preserving typo detection for direct object literals and wider
259
+ * option variables.
260
+ */
261
+ type RejectUnknownRunOptionKeys<TOptions> = [TOptions] extends [undefined] ? unknown : Exclude<keyof TOptions, keyof RunOptions> extends never ? unknown : never;
262
+ /**
263
+ * Accepts only values typed exactly as `RunOptions`, which are widened to the
264
+ * conservative fallback overloads because they may hide context presence.
265
+ */
266
+ type AcceptExactRunOptions<TOptions> = [TOptions] extends [RunOptions] ? [RunOptions] extends [TOptions] ? unknown : never : never;
267
+ /**
268
+ * Accepts only values typed exactly as `RunOptions | undefined`, which model
269
+ * optional forwarding wrappers without widening generic Program overloads.
270
+ */
271
+ type AcceptExactOptionalRunOptions<TOptions> = [TOptions] extends [RunOptions | undefined] ? [RunOptions | undefined] extends [TOptions] ? unknown : never : never;
223
272
  /**
224
273
  * Runs a command-line parser with automatic process integration.
225
274
  *
@@ -285,8 +334,25 @@ type CompletionOptions = CompletionOptionsBoth | CompletionOptionsSingular | Com
285
334
  *
286
335
  * @since 0.11.0 Added support for {@link Program} objects.
287
336
  */
288
- declare function run<T>(program: Program<"sync", T>, options?: RunOptions): T;
289
- declare function run<T>(program: Program<"async", T>, options?: RunOptions): Promise<T>;
337
+ declare function run<T extends Parser<Mode, unknown, unknown>, const TContexts extends NonEmptySourceContexts>(parser: T, options: RunOptions & {
338
+ readonly contexts: TContexts;
339
+ } & ContextOptionsParam<TContexts, InferValue<T>>): Promise<InferValue<T>>;
340
+ declare function run<T extends Parser<Mode, unknown, unknown>, const TContexts extends readonly SourceContext<unknown>[]>(parser: T, options: RunOptions & {
341
+ readonly contexts: TContexts;
342
+ } & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, InferValue<T>>): ModeValue<InferMode<T>, InferValue<T>> | Promise<InferValue<T>>;
343
+ declare function run<M extends Mode, T, const TContexts extends NonEmptySourceContexts>(program: Program<M, T>, options: RunOptions & {
344
+ readonly contexts: TContexts;
345
+ } & ContextOptionsParam<TContexts, T>): Promise<T>;
346
+ declare function run<T, const TContexts extends readonly SourceContext<unknown>[]>(program: Program<"sync", T>, options: RunOptions & {
347
+ readonly contexts: TContexts;
348
+ } & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, T>): T | Promise<T>;
349
+ declare function run<T, const TContexts extends readonly SourceContext<unknown>[]>(program: Program<"async", T>, options: RunOptions & {
350
+ readonly contexts: TContexts;
351
+ } & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, T>): Promise<T>;
352
+ declare function run<T, const TOptions extends RunOptions | undefined>(program: Program<"sync", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): T;
353
+ declare function run<T, TOptions extends RunOptions>(program: Program<"sync", T>, options: TOptions & AcceptExactRunOptions<TOptions>): T | Promise<T>;
354
+ declare function run<T, const TOptions extends RunOptions | undefined>(program: Program<"async", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): Promise<T>;
355
+ declare function run<T, TOptions extends RunOptions>(program: Program<"async", T>, options: TOptions & AcceptExactRunOptions<TOptions>): Promise<T>;
290
356
  declare function run<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
291
357
  declare function run<T extends Parser<"async", unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
292
358
  declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): ModeValue<InferMode<T>, InferValue<T>>;
@@ -303,7 +369,15 @@ declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, option
303
369
  * @returns The parsed result if successful.
304
370
  * @since 0.9.0
305
371
  */
306
- declare function runSync<T>(program: Program<"sync", T>, options?: RunOptions): T;
372
+ declare function runSync<T extends Parser<"sync", unknown, unknown>, TContexts extends readonly SourceContext<unknown>[]>(parser: T, options: RunOptions & {
373
+ readonly contexts: TContexts;
374
+ } & ContextOptionsParam<TContexts, InferValue<T>>): InferValue<T>;
375
+ declare function runSync<T, const TContexts extends readonly SourceContext<unknown>[]>(program: Program<"sync", T>, options: RunOptions & {
376
+ readonly contexts: TContexts;
377
+ } & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, T>): T;
378
+ declare function runSync<T, const TOptions extends RunOptions | undefined>(program: Program<"sync", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): T;
379
+ declare function runSync<T, TOptions extends RunOptions>(program: Program<"sync", T>, options: TOptions & AcceptExactRunOptions<TOptions>): T;
380
+ declare function runSync<T, TOptions extends RunOptions | undefined>(program: Program<"sync", T>, options: TOptions & AcceptExactOptionalRunOptions<TOptions>): T;
307
381
  declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T, options?: RunOptions): InferValue<T>;
308
382
  /**
309
383
  * Runs an asynchronous command-line parser with automatic process integration.
@@ -318,8 +392,16 @@ declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T,
318
392
  * @returns A Promise of the parsed result if successful.
319
393
  * @since 0.9.0
320
394
  */
321
- declare function runAsync<T>(program: Program<"sync", T>, options?: RunOptions): Promise<T>;
322
- declare function runAsync<T>(program: Program<"async", T>, options?: RunOptions): Promise<T>;
395
+ declare function runAsync<T extends Parser<Mode, unknown, unknown>, TContexts extends readonly SourceContext<unknown>[]>(parser: T, options: RunOptions & {
396
+ readonly contexts: TContexts;
397
+ } & ContextOptionsParam<TContexts, InferValue<T>>): Promise<InferValue<T>>;
398
+ declare function runAsync<M extends Mode, T, const TContexts extends readonly SourceContext<unknown>[]>(program: Program<M, T>, options: RunOptions & {
399
+ readonly contexts: TContexts;
400
+ } & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, T>): Promise<T>;
401
+ declare function runAsync<T, const TOptions extends RunOptions | undefined>(program: Program<"sync", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): Promise<T>;
402
+ declare function runAsync<T, const TOptions extends RunOptions | undefined>(program: Program<"async", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): Promise<T>;
403
+ declare function runAsync<T, TOptions extends RunOptions>(program: Program<Mode, T>, options: TOptions & AcceptExactRunOptions<TOptions>): Promise<T>;
404
+ declare function runAsync<T, TOptions extends RunOptions | undefined>(program: Program<Mode, T>, options: TOptions & AcceptExactOptionalRunOptions<TOptions>): Promise<T>;
323
405
  declare function runAsync<T extends Parser<Mode, unknown, unknown>>(parser: T, options?: RunOptions): Promise<InferValue<T>>;
324
406
  //#endregion
325
407
  export { RunOptions, run, runAsync, runSync };