@optique/run 1.0.0-dev.908 → 1.0.0-dev.921
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 +2 -35
- package/dist/run.d.cts +19 -10
- package/dist/run.d.ts +19 -10
- package/dist/run.js +2 -35
- package/package.json +2 -2
package/dist/run.cjs
CHANGED
|
@@ -38,11 +38,9 @@ function runSync(parserOrProgram, options = {}) {
|
|
|
38
38
|
const { parser, programMetadata } = resolved;
|
|
39
39
|
options = resolved.options;
|
|
40
40
|
const { programName, args, coreOptions } = buildCoreOptions(options, programMetadata);
|
|
41
|
-
const contextOptions = {};
|
|
42
|
-
for (const key of Object.keys(options)) if (!knownRunOptionsKeys.has(key)) contextOptions[key] = options[key];
|
|
43
41
|
const runWithOptions = {
|
|
44
42
|
...coreOptions,
|
|
45
|
-
|
|
43
|
+
contextOptions: options.contextOptions,
|
|
46
44
|
args
|
|
47
45
|
};
|
|
48
46
|
return (0, __optique_core_facade.runWithSync)(parser, programName, contexts, runWithOptions);
|
|
@@ -173,35 +171,6 @@ function buildCoreOptions(options, programMetadata) {
|
|
|
173
171
|
coreOptions
|
|
174
172
|
};
|
|
175
173
|
}
|
|
176
|
-
/**
|
|
177
|
-
* Set of known RunOptions field names. Used by `runImpl()` to separate
|
|
178
|
-
* RunOptions fields from context-required options via rest-spread.
|
|
179
|
-
*/
|
|
180
|
-
const knownRunOptionsKeyList = [
|
|
181
|
-
"programName",
|
|
182
|
-
"args",
|
|
183
|
-
"stdout",
|
|
184
|
-
"stderr",
|
|
185
|
-
"onExit",
|
|
186
|
-
"colors",
|
|
187
|
-
"maxWidth",
|
|
188
|
-
"showDefault",
|
|
189
|
-
"showChoices",
|
|
190
|
-
"sectionOrder",
|
|
191
|
-
"help",
|
|
192
|
-
"version",
|
|
193
|
-
"completion",
|
|
194
|
-
"aboveError",
|
|
195
|
-
"errorExitCode",
|
|
196
|
-
"brief",
|
|
197
|
-
"description",
|
|
198
|
-
"examples",
|
|
199
|
-
"author",
|
|
200
|
-
"bugs",
|
|
201
|
-
"footer",
|
|
202
|
-
"contexts"
|
|
203
|
-
];
|
|
204
|
-
const knownRunOptionsKeys = new Set(knownRunOptionsKeyList);
|
|
205
174
|
function runImpl(parserOrProgram, options = {}) {
|
|
206
175
|
const resolved = resolveProgramInput(parserOrProgram, options);
|
|
207
176
|
const { parser, programMetadata } = resolved;
|
|
@@ -209,11 +178,9 @@ function runImpl(parserOrProgram, options = {}) {
|
|
|
209
178
|
const contexts = options.contexts;
|
|
210
179
|
if (contexts && contexts.length > 0) {
|
|
211
180
|
const { programName: programName$1, args: args$1, coreOptions: coreOptions$1 } = buildCoreOptions(options, programMetadata);
|
|
212
|
-
const contextOptions = {};
|
|
213
|
-
for (const key of Object.keys(options)) if (!knownRunOptionsKeys.has(key)) contextOptions[key] = options[key];
|
|
214
181
|
const runWithOptions = {
|
|
215
182
|
...coreOptions$1,
|
|
216
|
-
|
|
183
|
+
contextOptions: options.contextOptions,
|
|
217
184
|
args: args$1
|
|
218
185
|
};
|
|
219
186
|
return (0, __optique_core_facade.runWith)(parser, programName$1, contexts, runWithOptions);
|
package/dist/run.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ShellCompletion } from "@optique/core/completion";
|
|
2
2
|
import { SourceContext } from "@optique/core/context";
|
|
3
|
-
import { CommandSubConfig,
|
|
3
|
+
import { CommandSubConfig, ContextOptionsParam, OptionSubConfig } from "@optique/core/facade";
|
|
4
4
|
import { InferMode, InferValue, Mode, ModeValue, Parser } from "@optique/core/parser";
|
|
5
5
|
import { Program } from "@optique/core/program";
|
|
6
6
|
import { DocSection, ShowChoicesOptions, ShowDefaultOptions } from "@optique/core/doc";
|
|
@@ -225,6 +225,15 @@ interface RunOptions {
|
|
|
225
225
|
* @since 1.0.0
|
|
226
226
|
*/
|
|
227
227
|
readonly contexts?: readonly SourceContext<unknown>[];
|
|
228
|
+
/**
|
|
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`.
|
|
233
|
+
*
|
|
234
|
+
* @since 1.0.0
|
|
235
|
+
*/
|
|
236
|
+
readonly contextOptions?: Record<string, unknown>;
|
|
228
237
|
}
|
|
229
238
|
/**
|
|
230
239
|
* Rejects context tuples that are statically known to be empty so those calls
|
|
@@ -327,19 +336,19 @@ type AcceptExactOptionalRunOptions<TOptions> = [TOptions] extends [RunOptions |
|
|
|
327
336
|
*/
|
|
328
337
|
declare function run<T extends Parser<Mode, unknown, unknown>, const TContexts extends NonEmptySourceContexts>(parser: T, options: RunOptions & {
|
|
329
338
|
readonly contexts: TContexts;
|
|
330
|
-
} &
|
|
339
|
+
} & ContextOptionsParam<TContexts, InferValue<T>>): Promise<InferValue<T>>;
|
|
331
340
|
declare function run<T extends Parser<Mode, unknown, unknown>, const TContexts extends readonly SourceContext<unknown>[]>(parser: T, options: RunOptions & {
|
|
332
341
|
readonly contexts: TContexts;
|
|
333
|
-
} & RejectEmptyContexts<TContexts> &
|
|
342
|
+
} & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, InferValue<T>>): ModeValue<InferMode<T>, InferValue<T>> | Promise<InferValue<T>>;
|
|
334
343
|
declare function run<M extends Mode, T, const TContexts extends NonEmptySourceContexts>(program: Program<M, T>, options: RunOptions & {
|
|
335
344
|
readonly contexts: TContexts;
|
|
336
|
-
} &
|
|
345
|
+
} & ContextOptionsParam<TContexts, T>): Promise<T>;
|
|
337
346
|
declare function run<T, const TContexts extends readonly SourceContext<unknown>[]>(program: Program<"sync", T>, options: RunOptions & {
|
|
338
347
|
readonly contexts: TContexts;
|
|
339
|
-
} & RejectEmptyContexts<TContexts> &
|
|
348
|
+
} & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, T>): T | Promise<T>;
|
|
340
349
|
declare function run<T, const TContexts extends readonly SourceContext<unknown>[]>(program: Program<"async", T>, options: RunOptions & {
|
|
341
350
|
readonly contexts: TContexts;
|
|
342
|
-
} & RejectEmptyContexts<TContexts> &
|
|
351
|
+
} & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, T>): Promise<T>;
|
|
343
352
|
declare function run<T, const TOptions extends RunOptions | undefined>(program: Program<"sync", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): T;
|
|
344
353
|
declare function run<T, TOptions extends RunOptions>(program: Program<"sync", T>, options: TOptions & AcceptExactRunOptions<TOptions>): T | Promise<T>;
|
|
345
354
|
declare function run<T, const TOptions extends RunOptions | undefined>(program: Program<"async", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): Promise<T>;
|
|
@@ -362,10 +371,10 @@ declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, option
|
|
|
362
371
|
*/
|
|
363
372
|
declare function runSync<T extends Parser<"sync", unknown, unknown>, TContexts extends readonly SourceContext<unknown>[]>(parser: T, options: RunOptions & {
|
|
364
373
|
readonly contexts: TContexts;
|
|
365
|
-
} &
|
|
374
|
+
} & ContextOptionsParam<TContexts, InferValue<T>>): InferValue<T>;
|
|
366
375
|
declare function runSync<T, const TContexts extends readonly SourceContext<unknown>[]>(program: Program<"sync", T>, options: RunOptions & {
|
|
367
376
|
readonly contexts: TContexts;
|
|
368
|
-
} & RejectEmptyContexts<TContexts> &
|
|
377
|
+
} & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, T>): T;
|
|
369
378
|
declare function runSync<T, const TOptions extends RunOptions | undefined>(program: Program<"sync", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): T;
|
|
370
379
|
declare function runSync<T, TOptions extends RunOptions>(program: Program<"sync", T>, options: TOptions & AcceptExactRunOptions<TOptions>): T;
|
|
371
380
|
declare function runSync<T, TOptions extends RunOptions | undefined>(program: Program<"sync", T>, options: TOptions & AcceptExactOptionalRunOptions<TOptions>): T;
|
|
@@ -385,10 +394,10 @@ declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T,
|
|
|
385
394
|
*/
|
|
386
395
|
declare function runAsync<T extends Parser<Mode, unknown, unknown>, TContexts extends readonly SourceContext<unknown>[]>(parser: T, options: RunOptions & {
|
|
387
396
|
readonly contexts: TContexts;
|
|
388
|
-
} &
|
|
397
|
+
} & ContextOptionsParam<TContexts, InferValue<T>>): Promise<InferValue<T>>;
|
|
389
398
|
declare function runAsync<M extends Mode, T, const TContexts extends readonly SourceContext<unknown>[]>(program: Program<M, T>, options: RunOptions & {
|
|
390
399
|
readonly contexts: TContexts;
|
|
391
|
-
} & RejectEmptyContexts<TContexts> &
|
|
400
|
+
} & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, T>): Promise<T>;
|
|
392
401
|
declare function runAsync<T, const TOptions extends RunOptions | undefined>(program: Program<"sync", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): Promise<T>;
|
|
393
402
|
declare function runAsync<T, const TOptions extends RunOptions | undefined>(program: Program<"async", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): Promise<T>;
|
|
394
403
|
declare function runAsync<T, TOptions extends RunOptions>(program: Program<Mode, T>, options: TOptions & AcceptExactRunOptions<TOptions>): Promise<T>;
|
package/dist/run.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandSubConfig,
|
|
1
|
+
import { CommandSubConfig, ContextOptionsParam, OptionSubConfig } from "@optique/core/facade";
|
|
2
2
|
import { Message } from "@optique/core/message";
|
|
3
3
|
import { ShellCompletion } from "@optique/core/completion";
|
|
4
4
|
import { SourceContext } from "@optique/core/context";
|
|
@@ -225,6 +225,15 @@ interface RunOptions {
|
|
|
225
225
|
* @since 1.0.0
|
|
226
226
|
*/
|
|
227
227
|
readonly contexts?: readonly SourceContext<unknown>[];
|
|
228
|
+
/**
|
|
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`.
|
|
233
|
+
*
|
|
234
|
+
* @since 1.0.0
|
|
235
|
+
*/
|
|
236
|
+
readonly contextOptions?: Record<string, unknown>;
|
|
228
237
|
}
|
|
229
238
|
/**
|
|
230
239
|
* Rejects context tuples that are statically known to be empty so those calls
|
|
@@ -327,19 +336,19 @@ type AcceptExactOptionalRunOptions<TOptions> = [TOptions] extends [RunOptions |
|
|
|
327
336
|
*/
|
|
328
337
|
declare function run<T extends Parser<Mode, unknown, unknown>, const TContexts extends NonEmptySourceContexts>(parser: T, options: RunOptions & {
|
|
329
338
|
readonly contexts: TContexts;
|
|
330
|
-
} &
|
|
339
|
+
} & ContextOptionsParam<TContexts, InferValue<T>>): Promise<InferValue<T>>;
|
|
331
340
|
declare function run<T extends Parser<Mode, unknown, unknown>, const TContexts extends readonly SourceContext<unknown>[]>(parser: T, options: RunOptions & {
|
|
332
341
|
readonly contexts: TContexts;
|
|
333
|
-
} & RejectEmptyContexts<TContexts> &
|
|
342
|
+
} & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, InferValue<T>>): ModeValue<InferMode<T>, InferValue<T>> | Promise<InferValue<T>>;
|
|
334
343
|
declare function run<M extends Mode, T, const TContexts extends NonEmptySourceContexts>(program: Program<M, T>, options: RunOptions & {
|
|
335
344
|
readonly contexts: TContexts;
|
|
336
|
-
} &
|
|
345
|
+
} & ContextOptionsParam<TContexts, T>): Promise<T>;
|
|
337
346
|
declare function run<T, const TContexts extends readonly SourceContext<unknown>[]>(program: Program<"sync", T>, options: RunOptions & {
|
|
338
347
|
readonly contexts: TContexts;
|
|
339
|
-
} & RejectEmptyContexts<TContexts> &
|
|
348
|
+
} & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, T>): T | Promise<T>;
|
|
340
349
|
declare function run<T, const TContexts extends readonly SourceContext<unknown>[]>(program: Program<"async", T>, options: RunOptions & {
|
|
341
350
|
readonly contexts: TContexts;
|
|
342
|
-
} & RejectEmptyContexts<TContexts> &
|
|
351
|
+
} & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, T>): Promise<T>;
|
|
343
352
|
declare function run<T, const TOptions extends RunOptions | undefined>(program: Program<"sync", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): T;
|
|
344
353
|
declare function run<T, TOptions extends RunOptions>(program: Program<"sync", T>, options: TOptions & AcceptExactRunOptions<TOptions>): T | Promise<T>;
|
|
345
354
|
declare function run<T, const TOptions extends RunOptions | undefined>(program: Program<"async", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): Promise<T>;
|
|
@@ -362,10 +371,10 @@ declare function run<T extends Parser<Mode, unknown, unknown>>(parser: T, option
|
|
|
362
371
|
*/
|
|
363
372
|
declare function runSync<T extends Parser<"sync", unknown, unknown>, TContexts extends readonly SourceContext<unknown>[]>(parser: T, options: RunOptions & {
|
|
364
373
|
readonly contexts: TContexts;
|
|
365
|
-
} &
|
|
374
|
+
} & ContextOptionsParam<TContexts, InferValue<T>>): InferValue<T>;
|
|
366
375
|
declare function runSync<T, const TContexts extends readonly SourceContext<unknown>[]>(program: Program<"sync", T>, options: RunOptions & {
|
|
367
376
|
readonly contexts: TContexts;
|
|
368
|
-
} & RejectEmptyContexts<TContexts> &
|
|
377
|
+
} & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, T>): T;
|
|
369
378
|
declare function runSync<T, const TOptions extends RunOptions | undefined>(program: Program<"sync", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): T;
|
|
370
379
|
declare function runSync<T, TOptions extends RunOptions>(program: Program<"sync", T>, options: TOptions & AcceptExactRunOptions<TOptions>): T;
|
|
371
380
|
declare function runSync<T, TOptions extends RunOptions | undefined>(program: Program<"sync", T>, options: TOptions & AcceptExactOptionalRunOptions<TOptions>): T;
|
|
@@ -385,10 +394,10 @@ declare function runSync<T extends Parser<"sync", unknown, unknown>>(parser: T,
|
|
|
385
394
|
*/
|
|
386
395
|
declare function runAsync<T extends Parser<Mode, unknown, unknown>, TContexts extends readonly SourceContext<unknown>[]>(parser: T, options: RunOptions & {
|
|
387
396
|
readonly contexts: TContexts;
|
|
388
|
-
} &
|
|
397
|
+
} & ContextOptionsParam<TContexts, InferValue<T>>): Promise<InferValue<T>>;
|
|
389
398
|
declare function runAsync<M extends Mode, T, const TContexts extends readonly SourceContext<unknown>[]>(program: Program<M, T>, options: RunOptions & {
|
|
390
399
|
readonly contexts: TContexts;
|
|
391
|
-
} & RejectEmptyContexts<TContexts> &
|
|
400
|
+
} & RejectEmptyContexts<TContexts> & ContextOptionsParam<TContexts, T>): Promise<T>;
|
|
392
401
|
declare function runAsync<T, const TOptions extends RunOptions | undefined>(program: Program<"sync", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): Promise<T>;
|
|
393
402
|
declare function runAsync<T, const TOptions extends RunOptions | undefined>(program: Program<"async", T>, options?: TOptions & RejectContextfulOptions<TOptions> & RejectUnknownRunOptionKeys<TOptions>): Promise<T>;
|
|
394
403
|
declare function runAsync<T, TOptions extends RunOptions>(program: Program<Mode, T>, options: TOptions & AcceptExactRunOptions<TOptions>): Promise<T>;
|
package/dist/run.js
CHANGED
|
@@ -37,11 +37,9 @@ function runSync(parserOrProgram, options = {}) {
|
|
|
37
37
|
const { parser, programMetadata } = resolved;
|
|
38
38
|
options = resolved.options;
|
|
39
39
|
const { programName, args, coreOptions } = buildCoreOptions(options, programMetadata);
|
|
40
|
-
const contextOptions = {};
|
|
41
|
-
for (const key of Object.keys(options)) if (!knownRunOptionsKeys.has(key)) contextOptions[key] = options[key];
|
|
42
40
|
const runWithOptions = {
|
|
43
41
|
...coreOptions,
|
|
44
|
-
|
|
42
|
+
contextOptions: options.contextOptions,
|
|
45
43
|
args
|
|
46
44
|
};
|
|
47
45
|
return runWithSync(parser, programName, contexts, runWithOptions);
|
|
@@ -172,35 +170,6 @@ function buildCoreOptions(options, programMetadata) {
|
|
|
172
170
|
coreOptions
|
|
173
171
|
};
|
|
174
172
|
}
|
|
175
|
-
/**
|
|
176
|
-
* Set of known RunOptions field names. Used by `runImpl()` to separate
|
|
177
|
-
* RunOptions fields from context-required options via rest-spread.
|
|
178
|
-
*/
|
|
179
|
-
const knownRunOptionsKeyList = [
|
|
180
|
-
"programName",
|
|
181
|
-
"args",
|
|
182
|
-
"stdout",
|
|
183
|
-
"stderr",
|
|
184
|
-
"onExit",
|
|
185
|
-
"colors",
|
|
186
|
-
"maxWidth",
|
|
187
|
-
"showDefault",
|
|
188
|
-
"showChoices",
|
|
189
|
-
"sectionOrder",
|
|
190
|
-
"help",
|
|
191
|
-
"version",
|
|
192
|
-
"completion",
|
|
193
|
-
"aboveError",
|
|
194
|
-
"errorExitCode",
|
|
195
|
-
"brief",
|
|
196
|
-
"description",
|
|
197
|
-
"examples",
|
|
198
|
-
"author",
|
|
199
|
-
"bugs",
|
|
200
|
-
"footer",
|
|
201
|
-
"contexts"
|
|
202
|
-
];
|
|
203
|
-
const knownRunOptionsKeys = new Set(knownRunOptionsKeyList);
|
|
204
173
|
function runImpl(parserOrProgram, options = {}) {
|
|
205
174
|
const resolved = resolveProgramInput(parserOrProgram, options);
|
|
206
175
|
const { parser, programMetadata } = resolved;
|
|
@@ -208,11 +177,9 @@ function runImpl(parserOrProgram, options = {}) {
|
|
|
208
177
|
const contexts = options.contexts;
|
|
209
178
|
if (contexts && contexts.length > 0) {
|
|
210
179
|
const { programName: programName$1, args: args$1, coreOptions: coreOptions$1 } = buildCoreOptions(options, programMetadata);
|
|
211
|
-
const contextOptions = {};
|
|
212
|
-
for (const key of Object.keys(options)) if (!knownRunOptionsKeys.has(key)) contextOptions[key] = options[key];
|
|
213
180
|
const runWithOptions = {
|
|
214
181
|
...coreOptions$1,
|
|
215
|
-
|
|
182
|
+
contextOptions: options.contextOptions,
|
|
216
183
|
args: args$1
|
|
217
184
|
};
|
|
218
185
|
return runWith(parser, programName$1, contexts, runWithOptions);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/run",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.921+754748bd",
|
|
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": "1.0.0-dev.
|
|
73
|
+
"@optique/core": "1.0.0-dev.921+754748bd"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/node": "^20.19.9",
|