Class: ArgvParser<TArgs>
The main parser class. This class is used to configure and parse arguments.
parser is a small helper function to create a new parser instance.
Type Parameters
• TArgs extends ParsedArgs
= object
Implements
ReadonlyArgvParser
<TArgs
>
Constructors
new ArgvParser()
new ArgvParser<
TArgs
>(options
?):ArgvParser
<TArgs
>
Creates a new parser. Normally using parser is preferred.
Parameters
• options?: ParserOptions
<TArgs
>
Returns
ArgvParser
<TArgs
>
Defined in
packages/parser/src/lib/parser.ts:134
Properties
configuredConflicts
configuredConflicts:
Record
<string
,Set
<string
>> ={}
The configured conflicts for the parser. If an option is set, and a conflicting option is also set, an error will be thrown.
Defined in
packages/parser/src/lib/parser.ts:102
configuredImplies
configuredImplies:
Record
<string
,Set
<string
>> ={}
The configured implies for the parser. If an option is set, the implied option must also be set.
Defined in
packages/parser/src/lib/parser.ts:107
configuredOptions
configuredOptions: { [key in string | number | symbol]: InternalOptionConfig }
The configured options for the parser.
Implementation of
ReadonlyArgvParser
.configuredOptions
Defined in
packages/parser/src/lib/parser.ts:92
configuredPositionals
configuredPositionals:
InternalOptionConfig
[]
The configured positional arguments for the parser
Implementation of
ReadonlyArgvParser
.configuredPositionals
Defined in
packages/parser/src/lib/parser.ts:97
options
options:
Required
<ParserOptions
<TArgs
>>
The configuration for the parser itself
Implementation of
Defined in
packages/parser/src/lib/parser.ts:112
parserMap
parserMap:
Record
<string
,Parser
<any
>>
The parsers used to parse individual option types.
Defined in
packages/parser/src/lib/parser.ts:117
Methods
asReadonly()
asReadonly():
ReadonlyArgvParser
<TArgs
>
Returns
ReadonlyArgvParser
<TArgs
>
Defined in
packages/parser/src/lib/parser.ts:552
augment()
augment<
TAugment
>(parser
):ArgvParser
<TArgs
&TAugment
>
Used to combine two parsers into a single parser. Mutates this
, but returns with updated typings
Type Parameters
• TAugment extends object
Parameters
• parser: ArgvParser
<TAugment
>
The parser to augment the current parser with.
Returns
ArgvParser
<TArgs
& TAugment
>
The updated parser instance.
Defined in
packages/parser/src/lib/parser.ts:526
clone()
clone(
parserOptions
):ArgvParser
<TArgs
>
Parameters
• parserOptions: ParserOptions
<TArgs
> = ...
Returns
ArgvParser
<TArgs
>
Defined in
packages/parser/src/lib/parser.ts:541
config()
config(
provider
):ArgvParser
<TArgs
>
Registers a configuration provider to read configuration from.
Parameters
• provider: ConfigurationProvider
<TArgs
>
The configuration provider to register.
Returns
ArgvParser
<TArgs
>
Defined in
packages/parser/src/lib/parser.ts:225
conflicts()
conflicts(...
options
):ArgvParser
<TArgs
>
Registers that a set of options cannot be provided at the same time.
Parameters
• ...options: [string
, string
, ...string[]
]
The options that cannot be provided together.
Returns
ArgvParser
<TArgs
>
Defined in
packages/parser/src/lib/parser.ts:496
env()
env(envPrefix)
env(
envPrefix
?):ArgvParser
<TArgs
>
Enables environment variable population for options.
Parameters
• envPrefix?: string
Prefix for environment variables. The full environment variable name will be ${envPrefix}_${optionName}
.
Returns
ArgvParser
<TArgs
>
Defined in
packages/parser/src/lib/parser.ts:204
env(options)
env(
options
):ArgvParser
<TArgs
>
Parameters
• options: EnvOptionConfig
Returns
ArgvParser
<TArgs
>
Defined in
packages/parser/src/lib/parser.ts:206
implies()
implies(
option
, ...options
):ArgvParser
<TArgs
>
Registers that the presence of one option implies the presence of one or more other options.
Parameters
• option: string
• ...options: string
[]
The options that imply the other option.
Returns
ArgvParser
<TArgs
>
Defined in
packages/parser/src/lib/parser.ts:513
option()
option<
TOption
,TOptionConfig
>(name
,config
):ArgvParser
<TArgs
&{ [key in string]: UndefinedIfRequiredAndNoDefault<TOptionConfig, InferTChoice<TOptionConfig> extends [never] ? TOptionConfig["coerce"] extends Function ? ReturnType<any[any]> : Object[TOptionConfig["type"]] : InferTChoice<TOptionConfig>> }
>
Registers a new option with the parser.
Type Parameters
• TOption extends string
• TOptionConfig extends OptionConfig
<any
>
Parameters
• name: TOption
The name of the option
• config: TOptionConfig
The configuration for the option. See OptionConfig
Returns
ArgvParser
<TArgs
& { [key in string]: UndefinedIfRequiredAndNoDefault<TOptionConfig, InferTChoice<TOptionConfig> extends [never] ? TOptionConfig["coerce"] extends Function ? ReturnType<any[any]> : Object[TOptionConfig["type"]] : InferTChoice<TOptionConfig>> }
>
Updated parser instance with the new option registered.
Defined in
packages/parser/src/lib/parser.ts:154
parse()
parse(
argv
):TArgs
Parses an array of arguments into a structured object.
Parameters
• argv: string
[] = ...
The array of arguments to parse
Returns
TArgs
The parsed arguments
Defined in
packages/parser/src/lib/parser.ts:235
positional()
positional<
TOption
,TOptionConfig
>(name
,config
):ArgvParser
<TArgs
&{ [key in string]: UndefinedIfRequiredAndNoDefault<TOptionConfig & Object, InferTChoice<TOptionConfig & Object> extends [never] ? (TOptionConfig & Object)["coerce"] extends Function ? ReturnType<any[any]> : Object[(TOptionConfig & Object)["type"]] : InferTChoice<TOptionConfig & Object>> }
>
Registers a new positional argument with the parser.
Type Parameters
• TOption extends string
• TOptionConfig extends OptionConfig
<any
>
Parameters
• name: TOption
The name of the positional argument
• config: TOptionConfig
The configuration for the positional argument. See OptionConfig
Returns
ArgvParser
<TArgs
& { [key in string]: UndefinedIfRequiredAndNoDefault<TOptionConfig & Object, InferTChoice<TOptionConfig & Object> extends [never] ? (TOptionConfig & Object)["coerce"] extends Function ? ReturnType<any[any]> : Object[(TOptionConfig & Object)["type"]] : InferTChoice<TOptionConfig & Object>> }
>
Updated parser instance with the new positional argument registered.