Emulationstation from batocera with configs and scripts for integration as Arch-Linux package
This project is maintained by GB609
This file contains a generic utility to define command line actions + arguments for them,
as well as the parser to map the input array into a more convenient structure.
It is also capable of some basic verifications to make sure required arguments were and - optionally -
that they are of a certain type.
The idea of this utility was to separate handling the logic of argument parsing and validation from their definition
to keep the command definitions as short and concise as possible.
But it should also allow extended configuration when needed (rarely).
Basic flow:
action(optionSpec, handler).handler which takes care of the pre-processing.process.argv.processOptionConfig(optionSpec) to evaluate which options and arguments are expected.OptionConfig will be passed to parseCmdLine(config, argv) to apply the configuration against the
the actually passed console arguments. The resulting [ParsedOptionDict] and the list of transformed/filtered positional
arguments are passed to the handler function.Any handler passed to api.action(optionSpec, handler) receives an instance of this class as first argument.
It’s mostly just a simple object, with a few convenience helpers for easier processing.
The keys used correspond to those of all named (=none-integer) options contained in optionSpec,
but the values are converted according the the validators used (if any).
Input: api.action({ '--flag': 0 }, ...)
Output: { '--flag' : true|false }
This is the main return value of parseCmdLine().
It is used internally in api.action() as intermediate class to transport the results of command line parsing.
Handler functions will get the contents of ParsedCmdLine.options as first argument and the entries of ParsedCmdLine.arguments
unpacked into separate varArgs.
options is [ParsedOptionDict]arguments is a mixed-type arryThis function uses the preprocessed [OptionConfig] to parse and transform the actual command line.
Argument values are transformed according to the Validators specified in the initial optionSpec.
This is a dictionary containing all known command line argument validators. These validators serve 2 purposes:
How to use:
optionSpec.optionSpec works in the section [processOptionConfig]But for most use cases, there is no need to use, touch or look at this dictionary.
Internally, validators can run in 2 different ‘modes’.
btc-config --help is used to print commands and their arguments.The object VALIDATORS itself is a {Proxy} with an implementation of get() which returns bound functions.
That way, argument configuration is attached to validators and the bound/pre-configured validators are used
when parsing the command line.
Check that the given number of arguments is still available to be parsed.
Configuration for optionSpec to use this is:
//simple variant - one argument
action({ optionName: # }, (options) => {})
//complex variant, allows to pass custom name prefix for the help function in addition to number of args
{ optionName: { argsRemaining: #, (#offset), string|function} }
# must be an integer number >= 0.#offset defines where to start numbering arguments in the generated help.# itself only works for string-named options, not for positional arguments. Such options will be considered as
boolean true/false flags.Bind does not allow to change this, but the resulting validator must be able to receive another this.
This function unpacks and inteprets the optionSpec given to [action]. It receives the first argument passed
to [action] and expects this to be a dictionary with a certain format.
{
<optionName> : validatorConfig|validatorName|typeSpec,
<#posInt>: validatorConfig|validatorName|typeSpec
#POS: int
}
Rules for keys:
<optionName>: any literal string, none-number string.<#posInt>: Numbers, or strings parsing as numbers. These are positional arguments, starting with 1.<optionName> or <#posInt> can be prefixed with ‘*’ to mark the given argument as required.Values:
| 0: [argsRemaining] - for string-named options: true | false flags |
Generated with shdoc from /opt/batocera-emulationstation/node_modules/cmdline/api.js