easy-cli-framework
Version:
A framework for building CLI applications that are robust and easy to maintain. Supports theming, configuration files, interactive prompts, and more.
80 lines (79 loc) • 2.74 kB
TypeScript
import { CommandSetupOptions, EasyCLICommand } from './command';
import { EasyCLIConfigFile } from '../config-files';
/**
* Options for the configure command
* @interface ConfigureCommandOptions
*
* @template TGlobalParams The global params for the CLI
* @template TParams The params for the command
*
* @property {string[]} globalKeysToUse What key(s) are you setting?
*
* @extends CommandSetupOptions
*
* @example
* ```typescript
* {
* globalKeysToUse?: string[]; // What key(s) are you setting?
* transformer?: (params: TGlobalParams & TParams) => any; // How to transform the params before saving
* alias?: string; // The alias for the command
* prompts?: {
* // Prompts to ask the user for an input for the env key
* env: {
* describe: 'What environent are you setting?',
* type: 'string',
* prompt: 'always',
* demandOption: true,
* },
* ...
* },
* }
* ```
*/
export type ConfigureCommandOptions<TGlobalParams, TParams> = CommandSetupOptions<TGlobalParams, TParams> & {
globalKeysToUse?: (keyof TGlobalParams)[];
callback?: (params: TGlobalParams & TParams) => void;
};
/**
* A command to add a configure command to the CLI that will save the configuration
*
* @template TParams The params for the command
* @template TGlobalParams The global params for the CLI
* @extends EasyCLICommand
*
* @example
* ```typescript
* new EasyCLIConfigureCommand(config, 'configure', {
* globalKeysToUse: ['verbose'], // Use the verbose key
* aliases: ['config', 'cfg', 'setup'] // Alias the command to 'config', 'cfg', and 'setup'
* prompts: {
* // Prompts to ask the user for an input for the env key
* env: {
* describe: 'What environent are you setting?',
* type: 'string',
* prompt: 'always',
* demandOption: true,
* },
* ...
* },
* flags: {
* // Add a flag to the command
* profile: {
* type: 'string',
* describe: 'The profile to use',
* demandOption: false, // Make the flag optional
* default: 'my-profile', // Set a default value
* }
* },
* });
* ```
*/
export declare class EasyCLIConfigureCommand<TParams extends Record<string, any> = Record<string, any>, TGlobalParams extends Record<string, any> = Record<string, any>> extends EasyCLICommand<TParams, TGlobalParams> {
/**
* Creates a new configure command
* @param {EasyCLIConfigFile} config The configuration file to use
* @param {string} [name='configure'] The name of the command
* @param {ConfigureCommandOptions<TGlobalParams, TParams>} [options={}] The options for the command
*/
constructor(config: EasyCLIConfigFile, name?: string, options?: ConfigureCommandOptions<TGlobalParams, TParams>);
}