Ƭ JsonArray: JsonValue
[]
Ƭ JsonObject: Object
▪ [key: string
]: JsonValue
Ƭ JsonPrimitive: string
| number
| boolean
| null
Ƭ JsonValue: JsonPrimitive
| JsonArray
| JsonObject
Ƭ Options: Object
Options object.
Name | Type | Description |
---|---|---|
allowSpacedValue? |
boolean |
Allow --key value syntax (without = ). |
handlers? |
{ bin? : () => string ; help? : true | (help : string ) => string | void ; inspect? : InspectOptions | (json : JsonObject ) => string | void ; json? : (json : JsonObject ) => string | void ; key? : (key : string ) => string ; merge? : (acc : JsonObject , next : JsonObject ) => JsonObject ; unkey? : (key : string ) => string ; unparse? : true | (args : string []) => string | void ; version? : () => string | void } |
Handlers for various actions. |
handlers.bin? |
() => string |
Function to return the CLI binary name. Used in the help text. Can query it from package.json for example. |
handlers.help? |
true | (help : string ) => string | void |
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. |
handlers.inspect? |
InspectOptions | (json : JsonObject ) => string | void |
Provide InspectOptions 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. |
handlers.json? |
(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. |
handlers.key? |
(key : string ) => string |
Function to convert CLI keys to JSON keys. If you need to convert from kebab-case to camelCase for example. |
handlers.merge? |
(acc : JsonObject , next : JsonObject ) => JsonObject |
Function to merge JSON objects that come from preset and json commands. Bring your own deep merger in case you need these commands. |
handlers.unkey? |
(key : string ) => string |
Function to convert JSON keys to CLI keys. If you need to convert from camelCase to kebab-case for example. |
handlers.unparse? |
true | (args : 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. |
handlers.version? |
() => string | void |
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. |
presets? |
{ [id: string] : { description : string ; json : JsonObject }; } |
Presets are pre-filled JSON objects. If supplied, this will enable preset command. Requires Options.handlers.merge to work. |
▸ handleArgs(args
, options?
): void
Parse arguments into JSON object, run required actions as defined in options object.
This function expects a stripped arguments array.
Use handleArgv instead in case you don't do anything with it.
Name | Type | Description |
---|---|---|
args |
string [] |
arguments array (for example process.argv.slice(2) ). |
options |
Options |
Options object. |
void
▸ handleArgv(options?
): void
Parse arguments into JSON object, run required actions as defined in options object.
This function uses process.argv
by itself.
Name | Type | Description |
---|---|---|
options |
Options |
Options object. |
void
▸ unparseArgs(json
, unkey?
): string
[]
Convert a JSON object into an equivalent array of arguments.
Name | Type | Description |
---|---|---|
json |
JsonObject |
JSON object to break down into arguments. |
unkey? |
(key : string ) => string |
A function to transform keys (for example change camel case of JSON keys to kebab case of CLI arguments). |
string
[]
An array of argument strings (unescaped, may require escaping specific to a shell).