UNPKG

kist

Version:

Package Pipeline Processor

63 lines (62 loc) 2.42 kB
import { AbstractProcess } from "../core/abstract/AbstractProcess"; import { OptionsInterface } from "../interface/OptionsInterface"; /** * ArgumentParser handles parsing and validating command-line arguments * against the structure defined in OptionsInterface. * Extends AbstractProcess for consistent logging. */ export declare class ArgumentParser extends AbstractProcess { /** * Command-line arguments to parse, excluding the Node.js and script path. */ private args; /** * Instance of OptionsValidator for validating parsed arguments. */ private validator; /** * Initializes the ArgumentParser with command-line arguments and an * instance of OptionsValidator for validation. * * @param args - Command-line arguments. Defaults to `process.argv.slice(2)`. */ constructor(); /** * Retrieves the value of a specific option from the CLI arguments, with * validation. * * @param key - The name of the option (matches keys in OptionsInterface). * @param options - Additional options: * - `default`: The default value to return if the option is not found. * @returns The value of the option or the default value if not found. * @throws Error if the value is invalid based on the validation rules. */ getOption<K extends keyof OptionsInterface>(key: K, options?: { default?: OptionsInterface[K]; }): OptionsInterface[K] | undefined; /** * Checks if a specific flag exists in the CLI arguments. * * @param key - The name of the flag to check (e.g., "dryRun"). * @returns `true` if the flag is present, otherwise `false`. */ hasFlag(key: keyof OptionsInterface): boolean; /** * Parses all CLI arguments into a key-value object. * Flags are treated as boolean if not followed by a value. * * Example: * --live --mode development => { live: true, mode: "development" } * * @returns A key-value object of all parsed CLI arguments. */ getAllFlags(): Record<string, string | boolean>; /** * Retrieves a specific flag value. * * @param key - The flag name to retrieve. * @param defaultValue - The default value if the flag is not present. * @returns The value of the flag or the default value. */ getFlag(key: string, defaultValue?: string | boolean): string | boolean; }