Constructs a new parser with empty state, ready for configuration.
The parser options to use
Optional
existingState: ArgsStateThe previous state to uses
Readonly
_stateReadonly
optsPrivate
positionalAdd a flag argument to the configuration. The first long flag is used as the key in the output object so must be given. Any aliases after that are just used as alternatives, and will not appear in the output object
If the key or any aliases exist in the config, this will throw.
this
The key and aliases to register
The argument to register
Adds a Command to the configuration. This will enable commands / subcommands (declared on the Command itself) to be recognised by the parser.
If a command is not recognised by the parser, it will refer to the ParserOpts.unrecognisedCommand option to determine what to do.
This will throw if the command or any of its aliases are already registered, or if it conflicts with the command triggers of a registered builtin.
this
The name and aliases to register
The command to register with
Whether to inherit arguments from this configuration into the parser
Appends or overwrites the footer lines, which are shown at the bottom of the help string.
this
The footer line to show
Whether to append, or overwrite
Private
intoPrivate
intoParses the provided arguments, printing the problems and exiting if the parse fails. Callers can use parseToResult if control of parse failure behaviour is required.
The result of the parse, never an error
The arguments to parse
Whether to execute discovered commands, or return them
Attempt to parse the provided arguments, returning the result of the operation. This is an alternative to parse, allowing the caller to control what happens in the event of parse failure.
The result of the parse
The arguments to parse
Whether to execute discovered commands, or return them
Add a positional Argument to the configuration. Conflict behaviour with commands is described in command If a positional exists with the provided key, this will throw.
this
The key to use for the positional, maps to the output object.
The argument to register
Validate that the schema is okay to use. This detects problems which cannot be detected at a type level. This may be expensive to call, so should not be used in production.
It is advised to run this in tests, and when your schema changes. If there are problems, and this is not called & handled, the behaviour of the parser is undefined.
SchemaError
if there is a problem, this
otherwise
Generated using TypeDoc
The root class for the library. Generally, it represents a configured parser which can then be used to parse arbitrary input strings.
It will hold all the state needed to parse inputs. This state is modified through the various helper methods defined on this class.