execOptions
execOptions parses CLI options and resolves the result as a { [optionName]: resultOption } record. If parsing fails, a detailed error is printed to the console. The --help / -h output is generated automatically from the declared options.
Example
ts
import { SC } from "@duplojs/server-utils";
import { DP } from "@duplojs/utils";
const portOption = SC.createOption(
"port",
DP.coerce.number(),
{
description: "HTTP port",
required: true,
},
);
const verboseOption = SC.createBooleanOption(
"verbose",
{
aliases: ["v"],
description: "Enable verbose logs",
},
);
const options = await SC.execOptions(portOption, verboseOption);
if (options.verbose) {
console.log(`server starts on ${options.port}`);
}Syntax
typescript
function execOptions<
GenericOptions extends [Option, ...Option[]]
>(
...options: GenericOptions
): Promise<ComputeResult<GenericOptions>>Parameters
options([Option, ...Option[]]) : options to parse from runtime arguments.
Return value
Promise<ComputeResult<GenericOptions>>: promise resolving to an object whose keys are option names and whose values are the typed result of each parser.
See also
exec- Runs a full command from runtime arguments.createBooleanOption- Builds a boolean flag option.createOption- Builds a single-value option.createArrayOption- Builds an array option.
