import { Type } from '../common/cli-types'; import { OptionDefinition, ParsedOption } from '../options/option-models'; import { ParameterDefinition } from '../parameters/parameter-models'; import { FilePath } from './additional-types'; import { AppContext } from '../app/app-context'; /** * Inject token for the type casting implementation * * @publicApi */ export declare const TYPE_CASTER: unique symbol; /** * Interface that describes the requirements for the type casting behavior. The implementation must * be able to cast and validate both option and parameter values, taking in metadata and returning * the cast value. The default implementation is the `DefaultTypeCaster`. * * @publicApi */ export interface TypeCaster { /** * Validates a parsed option value and casts it to the type specified in the option metadata * @param defintion Option metadata * @param parsed Options parsed from the raw cli arguments */ castOption(defintion: OptionDefinition, parsed: ParsedOption): any; /** * Validates a parsed parameter value and casts it to the type specified in the parameter metadata * @param defintion Parameter metadata * @param value Value parsed from the raw cli arguments */ castParameter(defintion: ParameterDefinition, value: any): any; } /** * Default implementation of the `TypeCaster` which provides the following behavior: * - Ability to validate and cast the string, number, boolean, `Int`, `FilePath` types * - Other types will not be cast and returned their original values * - The `Int` type only accepts integers while numbers accept decimal places * - The `FilePath` is a special type which validates as string input to a valid file or directory, * returning an absolute and relative path once cast * - Booleans accept the strings *'true'* or *'false'* and *'0'* or *'1'* */ export declare class DefaultTypeCaster implements TypeCaster { private process; /** * Creates a new instance * @param process Process that provides access the cwd */ constructor(process: AppContext); /** * Validates a parsed option value and casts it to the type specified in the option metadata * @param defintion Option metadata * @param value Option parsed from the raw cli arguments */ castOption(defintion: OptionDefinition, arg: ParsedOption): any; /** * Validates a parsed parameter value and casts it to the type specified in the parameter metadata * @param defintion Parameter metadata * @param value Value parsed from the raw cli arguments */ castParameter(defintion: ParameterDefinition, value: any): any; /** * Returns a string of the value, with pretty formatting if it is an array * @param value Value to be printed */ private printValue; /** * Validates and casts a value based on its design type * @param value Value to be cast * @param designType Constructor of the design type * @param isOption Whether the cast is for an option */ cast(value: any, designType: Type, isOption: boolean): any; /** * Casts to a string * @param value Value to be cast * @param isOption Whether the cast is for an option */ castString(value: any, isOption: boolean): string; /** * Casts to a file path * @param value Value to be cast */ castFilePath(value: any): FilePath; /** * Casts to a number that allows decimal places * @param value Value to be cast * @param isOption Whether the cast is for an option */ castNumber(value: any, isOption: boolean): number; /** * Casts to a number that does not allow decimal places * @param value Value to be cast * @param isOption Whether the cast is for an option */ castInt(value: any, isOption: boolean): number; /** * Casts to a boolean, accepting the strings *'true'* or *'false'* and *'0'* or *'1'* * @param value Value to be cast * @param isOption Whether the cast is for an option */ castBoolean(value: any, isOption: boolean): boolean; }