aspargvs
Version:
Parse argv as json object
108 lines (107 loc) • 4.27 kB
TypeScript
import { JsonObject } from './json';
/**
* Options object.
*/
export declare type Options = {
/** Allow `--key value` syntax (without `=`). */
allowSpacedValue?: boolean;
/** Handlers for various actions. */
handlers?: {
/**
* Set to `true` to enable built-in `help` command -
* `aspargvs` will print it's own help text.
*
* Provide a function to customize the help output - add app-specific information.
*
* `help` argument is the help text generated by `aspargvs`.
*
* If function returns a string then it will be sent to console.
* Otherwise it is considered handled by client code.
*/
help?: true | ((help: string) => (string | void));
/**
* Set to `true` to enable built-in unparse command -
* `aspargvs` will convert the parsed JSON object
* back into a list of argument strings and log it to console.
*
* Provide a function to customize the command.
*
* `args` array contains argument strings.
*
* If function returns a string then it will be sent to console.
* Otherwise it is considered handled by client code.
*/
unparse?: true | ((args: string[]) => (string | void));
/**
* Provide [InspectOptions](https://nodejs.org/api/util.html#utilinspectobject-options) object
* to enable built-in inspect command.
* `aspargvs` will log to console the output of
* `util.inspect` applied to the parsed JSON object
* with the specified options.
* `{ depth: 4 }` would be a simple practical example.
*
* Provide a function to customize the command - to use
* a custom serializer or to send the output elsewhere.
*
* If function returns a string then it will be sent to console.
* Otherwise it is considered handled by client code.
*/
inspect?: import('node:util').InspectOptions | ((json: JsonObject) => (string | void));
/**
* Function to handle the parsed JSON object.
*
* This is the main handler, business logic of the client package
* is supposed to be called from it.
*
* If function returns a string then it will be sent to console.
* Otherwise it is considered handled by client code.
*/
json?: ((json: JsonObject) => (string | void));
/**
* Function to merge JSON objects that come from `preset` and `json` commands.
*
* Bring your own deep merger in case you need these commands.
*/
merge?: ((acc: JsonObject, next: JsonObject) => JsonObject);
/**
* Function to convert CLI keys to JSON keys.
* If you need to convert from kebab-case to camelCase for example.
*/
key?: ((key: string) => string);
/**
* Function to convert JSON keys to CLI keys.
* If you need to convert from camelCase to kebab-case for example.
*/
unkey?: ((key: string) => string);
/**
* Specify this function to enable the version command.
*
* Can query the version from package.json for example.
*
* If function returns a string then it will be sent to console.
* Otherwise it is considered handled by client code.
*/
version?: (() => (string | void));
/**
* Function to return the CLI binary name.
* Used in the help text.
*
* Can query it from package.json for example.
*/
bin?: (() => string);
};
/**
* Presets are pre-filled JSON objects.
* If supplied, this will enable `preset` command.
*
* Requires {@link Options.handlers.merge} to work.
*/
presets?: {
[id: string]: {
/** Description shown in the help output. */
description: string;
/** JSON object. User-supplied arguments are merged with this object. */
json: JsonObject;
};
};
};