Function: resolveArgs()
Call Signature
export declare function resolveArgs<A extends Args>(args: A, tokens: ArgToken[], resolveArgs?: ResolveArgs & {
passthrough?: false;
}): {
values: ArgValues<A>;
positionals: string[];
rest: string[];
error: AggregateError | undefined;
explicit: ArgExplicitlyProvided<A>;
}Resolve command line arguments.
Type Parameters
| Name | Description |
|---|---|
A extends Args | Arguments, which is an object that defines the command line arguments. |
Parameters
| Name | Type | Description |
|---|---|---|
args | A | An arguments that contains arguments schema. |
tokens | ArgToken[] | An array of tokens. |
resolveArgs | ResolveArgs & { passthrough?: false } | An arguments that contains resolve arguments. (optional) |
Returns
object — An object that contains the values of the arguments, positional arguments, rest arguments, validation errors, and explicit provision status.
error
error: AggregateError | undefined;explicit
explicit: ArgExplicitlyProvided<A>;positionals
positionals: string[];rest
rest: string[];values
values: ArgValues<A>;Examples
// passed tokens: --port 3000
const { values, explicit } = resolveArgs({
port: {
type: 'number',
default: 8080
},
host: {
type: 'string',
default: 'localhost'
}
}, parsedTokens)
values.port // 3000
values.host // 'localhost'
explicit.port // true (explicitly provided)
explicit.host // false (not provided, fallback to default)Call Signature
export declare function resolveArgs<A extends Args>(args: A, tokens: ArgToken[], resolveArgs: ResolveArgs & {
passthrough: true;
}): {
values: ArgValues<A>;
positionals: string[];
rest: string[];
error: AggregateError | undefined;
explicit: ArgExplicitlyProvided<A>;
/**
* The indexes, in the arguments given to `parseArgs()`, of the arguments that the schema does not
* take, in ascending order. See {@link ResolveArgs.passthrough} for which arguments they are.
*/
passthroughIndices: number[];
}Resolve command line arguments, and give the indexes of the arguments that the schema does not take, with passthrough.
Type Parameters
| Name | Description |
|---|---|
A extends Args | Arguments, which is an object that defines the command line arguments. |
Parameters
| Name | Type | Description |
|---|---|---|
args | A | An arguments that contains arguments schema. |
tokens | ArgToken[] | An array of tokens. |
resolveArgs | ResolveArgs & { passthrough: true } | An arguments that contains resolve arguments, with passthrough: true. |
Returns
object — An object that contains the values of the arguments, positional arguments, rest arguments, validation errors, explicit provision status, and the indexes of the arguments that the schema does not take.
error
error: AggregateError | undefined;explicit
explicit: ArgExplicitlyProvided<A>;passthroughIndices
passthroughIndices: number[];The indexes, in the arguments given to parseArgs(), of the arguments that the schema does not take, in ascending order. See ResolveArgs.passthrough for which arguments they are.
positionals
positionals: string[];rest
rest: string[];values
values: ArgValues<A>;Examples
// passed tokens: exec run.js --watch src
const { values, passthroughIndices } = resolveArgs(
{ script: { type: 'positional' } },
parsedTokens,
{ skipPositional: 0, passthrough: true }
)
values.script // 'run.js'
passthroughIndices // [2, 3], the indexes of `--watch` and `src`Call Signature
export declare function resolveArgs<A extends Args>(args: A, tokens: ArgToken[], resolveArgs?: ResolveArgs): {
values: ArgValues<A>;
positionals: string[];
rest: string[];
error: AggregateError | undefined;
explicit: ArgExplicitlyProvided<A>;
/**
* Only with {@link ResolveArgs.passthrough | passthrough}.
*/
passthroughIndices?: number[];
}Resolve command line arguments, with passthrough that may be true or not, such as a boolean.
Type Parameters
| Name | Description |
|---|---|
A extends Args | Arguments, which is an object that defines the command line arguments. |
Parameters
| Name | Type | Description |
|---|---|---|
args | A | An arguments that contains arguments schema. |
tokens | ArgToken[] | An array of tokens. |
resolveArgs | ResolveArgs | An arguments that contains resolve arguments. (optional) |
Returns
object — The result of one of the overloads above, by whether passthrough is true.
error
error: AggregateError | undefined;explicit
explicit: ArgExplicitlyProvided<A>;passthroughIndices
passthroughIndices?: number[];Only with passthrough.
positionals
positionals: string[];rest
rest: string[];values
values: ArgValues<A>;