import { OptionDefinition, ParsedOption } from '../options/option-models'; import { ParserConfig } from './parser-config'; import { TypeCaster } from './type-caster'; /** * Inject token for the option parsing implementation * * @publicAPi */ export declare const OPTIONS_PARSER: unique symbol; /** * An option that has been validated, parsed and associated with metadata * * @publicApi */ export interface EvaluatedOption { /** * The option metadata */ definition: OptionDefinition; /** * Option value parsed from the raw argument */ value: any; } /** * Interface describing the requirements for an implementation of the option parsing behavior. Takes in the option metadata * specific to the executed command, together with parsed options evaulated from the `ArgumentsParser`. Its role is to validate and * associate the parsed options to the relevant metadata. The default implementation is the `DefaultOptionsParser`. * * @publicApi */ export interface OptionsParser { /** * Implementation of the option parsing behavior which takes in the option metadata specific to the executed command, * together with parsed options evaulated from the `ArgumentsParser`. Its role is to validate and associate * the parsed options to the relevant metadata. The default implementation is the `DefaultOptionsParser`. * @param definitions Option metadata specific to the executed command * @param options Options parsed from the raw cli arguments through the `ArgumentsParser` */ parseOptions(definitions: OptionDefinition[], options: ParsedOption[]): EvaluatedOption[]; } /** * The default implementation of the `OptionsParser` which provides the following behavior: * - Throws an `OptionParsingError` when one or more parsed arguments do not have associated metadata * and *ParserConfig.ignoreUnknownOptions* is set to false * - Throws an `OptionParsingError` when no parsed options are found for options that have *required* metadata set to true * - Throws an `OptionParsingError` when the raw options contain the same option that called by both its name and * alias * - Validates and casts the option values through the `TypeCaster` where (a) the option's *typeChecks* metadata is set to true * (b) the option's *typeChecks* metadata is undefined (or unset) and the *ParserConfig.applyTypeCasting* is set to true * * @publicApi */ export declare class DefaultOptionsParser implements OptionsParser { private config; private typeCaster; /** * Creates a new instance * @param config Parsing configuration for modifying the behavior * @param typeCaster Type casting implementation for validating and casting option values */ constructor(config: ParserConfig, typeCaster: TypeCaster); /** * Validates and associates parsed options with the relevant metadata * @param definitions Options metadata specific to the executed command * @param options Options parsed from the raw cli arguments through the `ArgumentsParser` */ parseOptions(definitions: OptionDefinition[], options: ParsedOption[]): EvaluatedOption[]; /** * Throws an `OptionParsingError` where there are remaining parsed options, without associated metadata, and these remaining options are not * allowed as specified in the *ParserConfig* * @param unknownOptions Parsed options that could not be assocated with metadata * @param allowed Whether unassociated options are permitted */ private noExtraOptions; /** * Throws an `OptionParsingError` where options that have *required* metadata cannot be associated with a parsed option * @param remainingOptions Option metadata not associated with a parsed option */ private noMissingOptions; /** * Checks that the same option has not been provided by the user with both its name and alias metadata * @param options All options parsed from the raw cli arguments through the `ArgumentsParser` * @param definition Option metadata for which the test will be performed * @param arg Parsed option that has already been associated with the metadata through either its name or alias */ private noUseOfAliasAndName; /** * Returns the metadata and the associated parsed value for an option. Makes use of the `TypeCaster` implementation * where neccessary * @param definition Option metadata * @param arg Parsed option * @param castTypes Whether type casting is applied globally */ private parseOption; }