@grandlinex/easy-cli
Version:
Cli lib to perform common tasks
130 lines (129 loc) • 3.46 kB
TypeScript
import { CMap } from '@grandlinex/core';
import { ShellCommand } from '../class/ShellComand.js';
export type ParamType = 'string' | 'number' | 'boolean' | 'path' | 'null';
export type ParamTypeRaw = number | boolean | string | null;
export interface IHandler<X = any> {
/**
* Get the command list
*/
getCmds(full?: boolean): ShellCommand[];
/**
* Get the script name
*/
getCmdName(): string;
/**
* Get the dev mode state
*/
isDev(): boolean;
/**
* Get the default interactive page size
*/
getPageSize(): number | undefined;
/**
* function triggered when the command is ended
*/
onEnd(): void;
/**
* get data from the command handler
*/
getData(): X | null;
/**
* Set a static value
* @param key
* @param value
*/
setStatic(key: string, value: any): void;
/**
*
* @param key
*/
getStatic(key: string): string;
}
export interface IArgs {
/**
* Get the command list
*/
getCmdList(): string[];
/**
* Get the length of the parameter map
*/
getLength(): number;
/**
* Get the parameter map
*/
getParameters(): CMap<string, ParamTypeRaw>;
/**
* Get the parameter
*/
getParameter<T extends ParamTypeRaw | undefined = ParamTypeRaw | undefined>(key: string): T;
/**
* Get the null parameter as a boolean
*/
getParameterNull(key: string): boolean;
}
export type BaseCMDOptionEl = {
key: ParamTypeRaw;
description?: string;
};
export type BaseCMDOption = ((handler: IHandler) => Promise<BaseCMDOptionEl[]>) | BaseCMDOptionEl[];
export declare function StricktOption(option: BaseCMDOption, handler: IHandler): Promise<BaseCMDOptionEl[]>;
export type BaseCMDProperty = {
/**
* The key of the parameter
*/
key: string;
/**
* Is the parameter required
*/
required: boolean;
/**
* The description of the parameter
*/
description?: string;
/**
* The default value of the parameter
*/
default?: ParamTypeRaw | (() => Promise<ParamTypeRaw>);
/**
* Validate the parameter
* @param input The input value
*/
validate?(input: ParamTypeRaw): boolean | string;
/**
* The options of the parameter
*/
options?: BaseCMDOption;
};
export type SimpleCMDProp = BaseCMDProperty & {
type: 'boolean' | 'null';
};
export type NumberCMDProp = BaseCMDProperty & {
type: 'number';
/**
* Open the editor for the parameter
*/
editor?: boolean;
};
export type StringCMDProp = BaseCMDProperty & {
type: 'string';
/**
* Open the editor for the parameter
*/
editor?: boolean;
prefill?: 'tab' | 'editable';
};
export type PathCMDProp = BaseCMDProperty & {
type: 'path';
/**
* If true, the path is a file only
*/
fileOnly?: boolean;
/**
* If true, the path is a directory only
*/
dirOnly?: boolean;
};
export type CmdProperty = SimpleCMDProp | PathCMDProp | NumberCMDProp | StringCMDProp;
export declare function getBoolOrUndefined(val: unknown, fallback?: boolean | undefined): Promise<boolean | undefined>;
export declare function getStringOrUndefined(val: unknown, fallback?: string | undefined): Promise<string | undefined>;
export declare function getNumberOrUndefined(val: unknown, fallback?: number | undefined): Promise<number | undefined>;