UNPKG

argparse-ts

Version:

Modern CLI arguments parser for node.js

120 lines (119 loc) 4.32 kB
import type { ArgConfig, ArgConfigExtended, ValueValidatorInterface } from "../types"; /** * Validates an argument configuration. * * @param config - The argument configuration. * @param usedArgs - A set of used argument names and aliases. * * @throws {ArgumentConfigError} - If the argument configuration is invalid. * * @category Utils * @category Validation */ export declare function validateArgConfig(config: ArgConfig, usedArgs: Set<string>): void; /** * Validates a positional argument configuration. * * @param config - The positional argument configuration. * * @throws {ArgumentConfigError} - If the positional argument configuration is invalid. * * @category Utils * @category Validation */ export declare function validatePositionalArgConfig(config: ArgConfig): void; /** * Validates an optional argument configuration. * * @param config - The optional argument configuration. * * @throws {ArgumentConfigError} - If the optional argument configuration is invalid. * * @category Utils * @category Validation */ export declare function validateOptionalArgConfig(config: ArgConfig): void; /** * Checks if there are enough positional values to satisfy the given argument * configuration and the remaining argument configurations. * * @param valuesStack - The remaining positional values. * @param argConfig - The current argument configuration. * @param remainingArgConfigs - The remaining argument configurations. * * @throws {ArgumentValueError} - If there are not enough positional values. * * @category Utils * @category Validation */ export declare function checkEnoughPositionalValues(valuesStack: string[], argConfig: ArgConfigExtended, remainingArgConfigs: ArgConfigExtended[]): void; /** * Checks if all positional values are used. * * @param valuesStack - The remaining positional values. * * @throws {ArgumentValueError} - If there are any remaining positional values. * * @category Utils * @category Validation */ export declare function checkAllPositionalValuesUsed(valuesStack: string[]): void; /** * Checks if all options in the parsed options are recognized according to the provided argument configurations. * * @param parsedOptions - A record of options that have been parsed. * @param argConfigs - A record of argument configurations against which the options are validated. * * @throws {ArgumentValueError} - If there are any unrecognized options. * * @category Utils * @category Validation */ export declare function checkAllOptionsRecognized(parsedOptions: Record<string, unknown>, argConfigs: Record<string, ArgConfigExtended | undefined>): void; /** * Creates a value validator based on the provided argument configuration. * * @param argConfig - The argument configuration to generate a value validator for. * * @returns A value validator that can be used to validate the argument value. * * @category Utils * @category Validation */ export declare function createValueValidator(argConfig: ArgConfigExtended): BaseValueValidator; /** * BaseValueValidator is an abstract class that implements the ValueValidatorInterface. * It provides basic validation functionalities for argument values. * * @category Validation */ declare abstract class BaseValueValidator implements ValueValidatorInterface { /** * The extended argument configuration used for validation. */ protected argConfig: ArgConfigExtended; /** * Constructs a BaseValueValidator with the provided argument configuration. * * @param argConfig - The extended configuration for the argument to validate. */ constructor(argConfig: ArgConfigExtended); /** * Validates the argument value before it is cast. * * @param value - The array of string values to validate. * @param isset - Whether the value is set. * * @throws ArgumentValueError - If the value is required but not set, or if empty values are not allowed. */ validateBeforeCast(value: string[], isset: boolean): void; /** * Validates the argument value after it has been cast. * * @param value - The casted value to validate. * * @throws ArgumentValueError - If the value is invalid according to the custom validator. */ validateAfterCast(value: unknown): void; } export {};