Files
portfolio2023/node_modules/@adonisjs/ace/build/src/Parser/index.d.ts
T
2023-11-24 22:35:41 +01:00

81 lines
2.8 KiB
TypeScript

import getopts from 'getopts';
import { CommandArg, CommandFlag, GlobalFlagHandler, CommandConstructorContract } from '../Contracts';
/**
* The job of the parser is to parse the command line values by taking
* the command `args`, `flags` and `globalFlags` into account.
*/
export declare class Parser {
private registeredFlags;
constructor(registeredFlags: {
[name: string]: CommandFlag & {
handler: GlobalFlagHandler;
};
});
/**
* Validate all the flags against the flags registered by the command
* or as global flags and disallow unknown flags.
*/
private scanForUnknownFlags;
/**
* Processes ace command flag to set the options for `getopts`.
* We just define the `alias` with getopts coz their default,
* string and boolean options produces the behavior we don't
* want.
*/
private preProcessFlag;
/**
* Casts a flag value to a boolean. The casting logic is driven
* by the behavior of "getopts"
*/
private castToBoolean;
/**
* Cast the value to a string. The casting logic is driven
* by the behavior of "getopts"
*
* - Convert numbers to string
* - Do not convert boolean to a string, since a flag without a value
* gets a boolean value, which is invalid
*/
private castToString;
/**
* Cast value to an array of string. The casting logic is driven
* by the behavior of "getopts"
*
* - Numeric values are converted to string of array
* - A string value is splitted by comma and trimmed.
* - An array is casted to an array of string values
*/
private castToArray;
/**
* Cast value to an array of numbers. The casting logic is driven
* by the behavior of "getopts".
*
* - Numeric values are wrapped to an array.
* - String is splitted by comma and each value is casted to a number
* - Each array value is casted to a number.
*/
private castToNumArray;
/**
* Cast value to a number. The casting logic is driven
* by the behavior of "getopts"
*
* - Boolean values are not allowed
* - A string is converted to a number
*/
private castToNumer;
/**
* Casts value of a flag to it's expected data type. These values
* are then later validated to ensure that casting was successful.
*/
processFlag(flag: CommandFlag, parsed: getopts.ParsedOptions, command?: CommandConstructorContract): void;
/**
* Validates the value to ensure that values are defined for
* required arguments.
*/
validateArg(arg: CommandArg, index: number, parsed: getopts.ParsedOptions, command: CommandConstructorContract): void;
/**
* Parses argv and executes the command and global flags handlers
*/
parse(argv: string[], command?: CommandConstructorContract): getopts.ParsedOptions;
}