import { Json, IConfig, IHash, JsonObject } from "merapi"; export interface ICommandOptions { noHelp? : boolean; isDefault? : boolean; } export interface IParseOptionsResult { args : string[]; unknown : string[]; } export interface IOption { flags : string; required : boolean; optional : boolean; bool : boolean; short? : string; long : string; description : string; } export interface ICommand extends NodeJS.EventEmitter { args : string[]; /** * Set the program version to `str`. * * This method auto-registers the "-V, --version" flag * which will print the version number when passed. * * @param {string} str * @param {string} [flags] * @returns {ICommand} for chaining */ version(str : string, flags? : string) : ICommand; /** * Add ICommand `name`. * * The `.action()` callback is invoked when the * ICommand `name` is specified via __ARGV__, * and the remaining arguments are applied to the * function for access. * * When the `name` is "*" an un-matched ICommand * will be passed as the first arg, followed by * the rest of __ARGV__ remaining. * * @example * program * .version('0.0.1') * .option('-C, --chdir ', 'change the working directory') * .option('-c, --config ', 'set config path. defaults to ./deploy.conf') * .option('-T, --no-tests', 'ignore test hook') * * program * .ICommand('setup') * .description('run remote setup ICommands') * .action(function() { * console.log('setup'); * }); * * program * .ICommand('exec ') * .description('run the given remote ICommand') * .action(function(cmd) { * console.log('exec "%s"', cmd); * }); * * program * .ICommand('teardown [otherDirs...]') * .description('run teardown ICommands') * .action(function(dir, otherDirs) { * console.log('dir "%s"', dir); * if (otherDirs) { * otherDirs.forEach(function (oDir) { * console.log('dir "%s"', oDir); * }); * } * }); * * program * .ICommand('*') * .description('deploy the given env') * .action(function(env) { * console.log('deploying "%s"', env); * }); * * program.parse(process.argv); * * @param {string} name * @param {string} [desc] for git-style sub-ICommands * @param {ICommandOptions} [opts] ICommand options * @returns {ICommand} the new ICommand */ command(name : string, desc? : string, opts? : ICommandOptions) : ICommand; /** * Define argument syntax for the top-level ICommand. * * @param {string} desc * @returns {ICommand} for chaining */ arguments(desc : string) : ICommand; /** * Parse expected `args`. * * For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`. * * @param {string[]} args * @returns {ICommand} for chaining */ parseExpectedArgs(args : string[]) : ICommand; /** * Register callback `fn` for the ICommand. * * @example * program * .ICommand('help') * .description('display verbose help') * .action(function() { * // output help here * }); * * @param {(...args: any[]) => void} fn * @returns {ICommand} for chaining */ action(fn : (...args : any[]) => void) : ICommand; /** * Define option with `flags`, `description` and optional * coercion `fn`. * * The `flags` string should contain both the short and long flags, * separated by comma, a pipe or space. The following are all valid * all will output this way when `--help` is used. * * "-p, --pepper" * "-p|--pepper" * "-p --pepper" * * @example * // simple boolean defaulting to false * program.option('-p, --pepper', 'add pepper'); * * --pepper * program.pepper * // => Boolean * * // simple boolean defaulting to true * program.option('-C, --no-cheese', 'remove cheese'); * * program.cheese * // => true * * --no-cheese * program.cheese * // => false * * // required argument * program.option('-C, --chdir ', 'change the working directory'); * * --chdir /tmp * program.chdir * // => "/tmp" * * // optional argument * program.option('-c, --cheese [type]', 'add cheese [marble]'); * * @param {string} flags * @param {string} [description] * @param {((arg1: any, arg2: any) => void) | RegExp} [fn] function or default * @param {*} [defaultValue] * @returns {ICommand} for chaining */ option(flags : string, description? : string, fn? : ((arg1 : any, arg2 : any) => void) | RegExp, defaultValue? : any) : ICommand; option(flags : string, description? : string, defaultValue? : any) : ICommand; /** * Allow unknown options on the ICommand line. * * @param {boolean} [arg] if `true` or omitted, no error will be thrown for unknown options. * @returns {ICommand} for chaining */ allowUnknownOption(arg? : boolean) : ICommand; /** * Parse `argv`, settings options and invoking ICommands when defined. * * @param {string[]} argv * @returns {ICommand} for chaining */ parse(argv : string[]) : ICommand; /** * Parse options from `argv` returning `argv` void of these options. * * @param {string[]} argv * @returns {ParseOptionsResult} */ parseOptions(argv : string[]) : IParseOptionsResult; /** * Return an object containing options as key-value pairs * * @returns {{[key: string]: string}} */ opts() : { [key : string] : string }; /** * Set the description to `str`. * * @param {string} str * @return {(ICommand | string)} */ description(str : string) : ICommand; description() : string; /** * Set an alias for the ICommand. * * @param {string} alias * @return {(ICommand | string)} */ alias(alias : string) : ICommand; alias() : string; /** * Set or get the ICommand usage. * * @param {string} str * @return {(ICommand | string)} */ usage(str : string) : ICommand; usage() : string; /** * Get the name of the ICommand. * * @return {string} */ name() : string; /** * Output help information for this ICommand. * * @param {() => void} [cb] Callback method */ outputHelp(cb? : () => void) : void; /** Output help information and exit. */ help() : void; } export interface ICommandList { [name : string] : ICommandDescriptor; } export interface ICommandDescriptor { type? : "group" | "command" | "alias"; desc? : string; middleware? : string[]; subcommands? : ICommandList; args? : string; params? : { [param : string] : { type : string, desc? : string, short? : string, bool? : boolean, value? : Json } }; handler? : string; alias? : string; } export interface ICompile { execDirectives(config : IConfig, basepath : string) : IConfig; execDirective(name : string, directive : any, dict : IHash, basepath : string) : void; } export interface IHelper { getFiles(dir : string, ending : string) : string[]; loadYaml(file : string) : JsonObject; dumpYaml(file : string, object : JsonObject) : void; copyAll() : void; compareTestResult(result : Json, expect : Json) : {field : string, expect : any, result : any}[]; setProp(prop : string, value : Json, options? : JsonObject) : void; getProp(prop : string, options? : JsonObject) : Json; toPromise(ctx : any, func : any, ...args : any[]) : Promise; createDirectory(path : string, mode? : number) : void; getCurrentToken() : JsonObject; loadYamlOrJsonFile(filePath : string) : JsonObject; dumpPackageJson(merapiDescriptor : IMerapiDescriptor) : void; inquirerPrompt(questions : JsonObject[]) : Promise; delete() : boolean; wrapError(error : any) : string; difference(object : any, base : any) : object; } export interface ITester { execIntentTest(yaml : any, botApi : any, botId : string, print : (text : string) => void) : Promise>; execStateTest(yaml : any, botApi : any, botId : string, print : (text : string) => void) : Promise>; execActionsTest(yaml : any, botApi : any, botId : string, print : (text : string) => void) : Promise>; execFlowTest(yaml : any, botApi : any, botId : string, print : (text : string) => void) : Promise>; } export interface IMerapiDescriptor { name : string; author? : string; componentsPath? : string; plugins? : string[]; httpPort? : number; servicePort? : number; main? : string; }