import { ParameterDefinition } from '../parameters/parameter-models'; import { ParserConfig } from './parser-config'; import { TypeCaster } from './type-caster'; /** * Inject token for the parameter parser implementation * * @publicAPi */ export declare const PARAMETERS_PARSER: unique symbol; /** * An parameter that has been validated, parsed and associated with metadata * * @publicApi */ export interface EvaluatedParameter { /** * The parameter metadata */ definition: ParameterDefinition; /** * The value parsed from the raw cli argument */ value: any; } /** * Interface describing the requirements for an implementation of the parameter parsing behavior. Takes in the parameter metadata * specific to the executed command, together with parameter values. Its role is to validate and associate the parameter values * to the relevant metadata. The default implementation is the `DefaultParameterParser`. * * @publicApi */ export interface ParameterParser { /** * Implementation of the parameter parsing behaviour that takes in the parameter metadata specific to the executed command, * together with parameter values. Its role is to validate and associate the parameter values to the relevant metadata. The * default implementation is the `DefaultParameterParser`. * @param definitions Parameter metadata specific to the executed command * @param parameters parameter values taken from the raw cli arguments after options and commands have been resolved */ parseParameters(definitions: ParameterDefinition[], parameters: string[]): EvaluatedParameter[]; } /** * Default implementation of the `ParameterParser` which provides the following behavior: * - Throws `ParameterParsingError` when required parameters a missing * - Throws `ParameterParsingError` when too many parameters have been provided and *ParserConfig.ignoreUnknownParameters* is false * - Validates and casts parameter values through the `TypeCaster` where (a) the parameter's *typeChecks* metadata is set to true * (b) the parameter's *typeChecks* is undefined (unset) and the *ParserConfig.applyTypeCasting* is set to true * * @publicApi */ export declare class DefaultParameterParser implements ParameterParser { 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 parameter values */ constructor(config: ParserConfig, typeCaster: TypeCaster); /** * Validates and associates parameter values with the relevant metadata * @param definitions Parameter metadata specific to the executed command * @param parameters Parameters from the raw cli arguments after the commands and options have been resolved */ parseParameters(definitions: ParameterDefinition[], parameters: string[]): EvaluatedParameter[]; /** * Returns the parameter metadata with its' parsed value. Makes use of the `TypeCaster` implementation * where neccessary * @param definition Parameter metadata * @param value Parameter value * @param castTypes Whether type casting is applied globally */ private parseParameter; }