ArgvParser
classclass 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.
Properties
| Name | Type | Description |
|---|---|---|
| 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. |
| configuredImplies | Record<string, Set<string>> | The configured implies for the parser. If an option is set, the implied option must also be set. |
| configuredOptions | { [key in string | number | symbol]: InternalOptionConfig } | The configured options for the parser. |
| configuredPositionals | InternalOptionConfig[] | The configured positional arguments for the parser |
| options | Required<ParserOptions<TArgs>> | The configuration for the parser itself |
| parserMap | Record<string, Parser<any>> | The parsers used to parse individual option types. |
Methods
asReadonly(): ReadonlyArgvParser<TArgs>augment(parser: ArgvParser<TAugment>): ArgvParser<TArgs & TAugment>Used to combine two parsers into a single parser. Mutates `this`, but returns with updated typings
clone(parserOptions: ParserOptions<TArgs>): ArgvParser<TArgs>config(provider: AnyConfigProvider<TArgs>): ArgvParser<TArgs>Registers a configuration provider to read configuration from.
conflicts(options: [string, string, ...string[]]): ArgvParser<TArgs>Registers that a set of options cannot be provided at the same time.
env(envPrefix?: string): ArgvParser<TArgs>Enables environment variable population for options.
getConfigurationDocs(): ConfigurationDocSection[]Gets documentation sections for all configured configuration providers.
getDisplayKey(key: string): stringGets the display key for an option, which may be localized.
getEnvInfo(): { enabled: boolean; prefix?: string }Returns the environment variable configuration for this parser, used by documentation generation.
getLocalizationDictionary(): LocalizationDictionary | undefinedGets the localization dictionary if configured.
implies(option: string, options: string[]): ArgvParser<TArgs>Registers that the presence of one option implies the presence of one or more other options.
localize(dictionary: LocalizationDictionary, locale?: string): thisSets up localization for option keys and other text. When localization is enabled, option keys will be displayed in the specified locale, but the default (non-localized) keys will still be accepted as aliases.
option(name: TOption, config: ObjectOptionConfig<TCoerce, TProps>): ArgvParser<TArgs & MakeUndefinedPropertiesOptional<{ [key in string]: unknown extends TCoerce ? ResolveProperties<TProps> : TCoerce }>>Registers a new option with the parser.
parse(argv: string[], alreadyParsed?: Record<string, unknown>): TArgsParses an array of arguments into a structured object.
positional(name: TOption, config: ObjectOptionConfig<TCoerce, TProps>): ArgvParser<TArgs & MakeUndefinedPropertiesOptional<{ [key in string]: unknown extends TCoerce ? ResolveProperties<TProps> : TCoerce }>>Registers a new positional argument with the parser.
strict(enable: boolean): ArgvParser<TArgs>Enables or disables strict mode. When strict mode is enabled, the parser throws a validation error when unmatched arguments are encountered. Unmatched arguments are those that don't match any configured option or positional argument.
updateConfig(values: Partial<TArgs>): Promise<void>Updates configuration values by routing each key to the provider that owns it.