mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 19:09:18 +08:00
apply formatter to commander
This commit is contained in:
@@ -8,28 +8,28 @@
|
||||
import program = require("commander");
|
||||
|
||||
program
|
||||
.version('0.0.1')
|
||||
.option('-C, --chdir <path>', 'change the working directory')
|
||||
.option('-c, --config <path>', 'set config path [./deploy.conf]')
|
||||
.option('-T, --no-tests', 'ignore test hook')
|
||||
.version('0.0.1')
|
||||
.option('-C, --chdir <path>', 'change the working directory')
|
||||
.option('-c, --config <path>', 'set config path [./deploy.conf]')
|
||||
.option('-T, --no-tests', 'ignore test hook')
|
||||
|
||||
// $ deploy setup stage
|
||||
// $ deploy setup
|
||||
program
|
||||
.command('setup [env]')
|
||||
.description('run setup commands for all envs')
|
||||
.action(function (env?) {
|
||||
env = env || 'all';
|
||||
console.log('setup for %s env(s)', env);
|
||||
});
|
||||
.command('setup [env]')
|
||||
.description('run setup commands for all envs')
|
||||
.action(function (env?) {
|
||||
env = env || 'all';
|
||||
console.log('setup for %s env(s)', env);
|
||||
});
|
||||
|
||||
// $ deploy stage
|
||||
// $ deploy production
|
||||
program
|
||||
.command('*')
|
||||
.action(function (env?) {
|
||||
console.log('deploying "%s"', env);
|
||||
});
|
||||
.command('*')
|
||||
.action(function (env?) {
|
||||
console.log('deploying "%s"', env);
|
||||
});
|
||||
|
||||
program.option('-p, --pepper', 'add pepper');
|
||||
|
||||
@@ -43,8 +43,11 @@ program.prompt('Description:', function (desc) {
|
||||
console.log('description was "%s"', desc.trim());
|
||||
});
|
||||
|
||||
program.promptForNumber("Enter a number:", (n) => { });
|
||||
program.promptForNumber("Enter a number:", (n) => {
|
||||
});
|
||||
|
||||
program.confirm("Confirm? ", (f) => { });
|
||||
program.confirm("Confirm? ", (f) => {
|
||||
});
|
||||
|
||||
program.choose(["a", "b", "c"], (i) => { });
|
||||
program.choose(["a", "b", "c"], (i) => {
|
||||
});
|
||||
|
||||
310
commander/commander.d.ts
vendored
310
commander/commander.d.ts
vendored
@@ -6,8 +6,8 @@
|
||||
declare module "commander" {
|
||||
export interface Command {
|
||||
/**
|
||||
* The command name.
|
||||
*/
|
||||
* The command name.
|
||||
*/
|
||||
name: string;
|
||||
|
||||
//
|
||||
@@ -20,103 +20,103 @@ declare module "commander" {
|
||||
//
|
||||
|
||||
/**
|
||||
* Register callback fn for the command.
|
||||
*/
|
||||
action(fn: (...args: any[]) => any): Command;
|
||||
* Register callback fn for the command.
|
||||
*/
|
||||
action(fn:(...args:any[]) => any): Command;
|
||||
|
||||
/**
|
||||
* Define option with flags, description and optional coercion function and default value.
|
||||
* 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"
|
||||
*
|
||||
* @param flags the option flags.
|
||||
* @param description the option description. The description is printed when "--help" is used.
|
||||
* @param coerceFn (optional) specifies a callback function to coerce the option arg.
|
||||
* @param defaultValue (optional) specifies a default value.
|
||||
*/
|
||||
option(flags: string, description: string, coerceFn?: (value: string) => any, defaultValue?: any): Command;
|
||||
* Define option with flags, description and optional coercion function and default value.
|
||||
* 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"
|
||||
*
|
||||
* @param flags the option flags.
|
||||
* @param description the option description. The description is printed when "--help" is used.
|
||||
* @param coerceFn (optional) specifies a callback function to coerce the option arg.
|
||||
* @param defaultValue (optional) specifies a default value.
|
||||
*/
|
||||
option(flags:string, description:string, coerceFn?:(value:string) => any, defaultValue?:any): Command;
|
||||
|
||||
|
||||
/**
|
||||
* Sets the command version
|
||||
*/
|
||||
version(version: string): Command;
|
||||
* Sets the command version
|
||||
*/
|
||||
version(version:string): Command;
|
||||
|
||||
/**
|
||||
* Parse the arguments array and invokes the commands passing the parsed options.
|
||||
* @param argv the arguments array.
|
||||
*/
|
||||
parse(argv: string[]): Command;
|
||||
* Parse the arguments array and invokes the commands passing the parsed options.
|
||||
* @param argv the arguments array.
|
||||
*/
|
||||
parse(argv:string[]): Command;
|
||||
|
||||
/**
|
||||
* Gets or sets the command description.
|
||||
* @param description the new description for the command. When ommited this returns the current description, otherwise returns the current Command.
|
||||
*/
|
||||
description(description: string): Command;
|
||||
* Gets or sets the command description.
|
||||
* @param description the new description for the command. When ommited this returns the current description, otherwise returns the current Command.
|
||||
*/
|
||||
description(description:string): Command;
|
||||
description(): string;
|
||||
|
||||
/**
|
||||
* Gets or sets the usage help string.
|
||||
*/
|
||||
usage(usage: string): Command;
|
||||
* Gets or sets the usage help string.
|
||||
*/
|
||||
usage(usage:string): Command;
|
||||
usage(): string;
|
||||
|
||||
/*
|
||||
* Prompt the user for a value, calling the callback function.
|
||||
*
|
||||
* Supports single-line and multi-line prompts.
|
||||
* To issue a single-line prompt simply add a whitespace
|
||||
* to the end of label, something like "name: ", whereas
|
||||
* for a multi-line prompt omit this "description:".
|
||||
* @param label the label string to be printed in console.
|
||||
* @param callback a callback function to handle the inputed string.
|
||||
*/
|
||||
prompt(label: string, callback: (value: string) => any): void;
|
||||
/**
|
||||
* Prompt the user for a value, calling the callback function.
|
||||
*
|
||||
* Supports single-line and multi-line prompts.
|
||||
* To issue a single-line prompt simply add a whitespace
|
||||
* to the end of label, something like "name: ", whereas
|
||||
* for a multi-line prompt omit this "description:".
|
||||
* @param label the label string to be printed in console.
|
||||
* @param callback a callback function to handle the inputed string.
|
||||
*/
|
||||
prompt(label:string, callback:(value:string) => any): void;
|
||||
|
||||
promptForNumber(label: string, callback: (value: number) => any): void;
|
||||
promptForDate(label: string, callback: (value: Date) => any): void;
|
||||
promptSingleLine(label: string, callback: (value: string) => any): void;
|
||||
promptMultiLine(label: string, callback: (value: string) => any): void;
|
||||
promptForNumber(label:string, callback:(value:number) => any): void;
|
||||
promptForDate(label:string, callback:(value:Date) => any): void;
|
||||
promptSingleLine(label:string, callback:(value:string) => any): void;
|
||||
promptMultiLine(label:string, callback:(value:string) => any): void;
|
||||
|
||||
/**
|
||||
* Prompt for password with a label, a optional mask char and callback function.
|
||||
* The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.
|
||||
*/
|
||||
password(label: string, mask: string, callback: (value: string) => any): void;
|
||||
password(label: string, callback: (value: string) => any): void;
|
||||
* Prompt for password with a label, a optional mask char and callback function.
|
||||
* The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.
|
||||
*/
|
||||
password(label:string, mask:string, callback:(value:string) => any): void;
|
||||
password(label:string, callback:(value:string) => any): void;
|
||||
|
||||
/**
|
||||
* Prompts the user for a confirmation.
|
||||
*/
|
||||
confirm(label: string, callback: (flag: boolean) => any): void;
|
||||
* Prompts the user for a confirmation.
|
||||
*/
|
||||
confirm(label:string, callback:(flag:boolean) => any): void;
|
||||
|
||||
/**
|
||||
* Prompt for password with str, mask char and callback fn(val).
|
||||
* The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.
|
||||
*/
|
||||
choose(options: string[], callback: (idx: number) => any): void;
|
||||
choose(options: any[], callback: (idx: number) => any): void;
|
||||
* Prompt for password with str, mask char and callback fn(val).
|
||||
* The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.
|
||||
*/
|
||||
choose(options:string[], callback:(idx:number) => any): void;
|
||||
choose(options:any[], callback:(idx:number) => any): void;
|
||||
|
||||
/**
|
||||
* Add command with the specified name. Returns a new instance of Command.
|
||||
*
|
||||
* The .action() callback is invoked when the
|
||||
* command name is specified via ARGV,
|
||||
* and the remaining arguments are applied to the
|
||||
* function for access.
|
||||
|
||||
* When the name is "*" an un-matched command
|
||||
* will be passed as the first arg, followed by
|
||||
* the rest of ARGV remaining.
|
||||
*
|
||||
* @param name the name of the command. Pass "*" to trap un-matched commands.
|
||||
*/
|
||||
command(name: string): Command;
|
||||
* Add command with the specified name. Returns a new instance of Command.
|
||||
*
|
||||
* The .action() callback is invoked when the
|
||||
* command name is specified via ARGV,
|
||||
* and the remaining arguments are applied to the
|
||||
* function for access.
|
||||
*
|
||||
* When the name is "*" an un-matched command
|
||||
* will be passed as the first arg, followed by
|
||||
* the rest of ARGV remaining.
|
||||
*
|
||||
* @param name the name of the command. Pass "*" to trap un-matched commands.
|
||||
*/
|
||||
command(name:string): Command;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -129,100 +129,108 @@ declare module "commander" {
|
||||
//
|
||||
|
||||
/**
|
||||
* Register callback fn for the command.
|
||||
*/
|
||||
export function action(fn: (...args: any[]) => any): Command;
|
||||
* Register callback fn for the command.
|
||||
*/
|
||||
export function action(fn:(...args:any[]) => any):Command;
|
||||
|
||||
/**
|
||||
* Define option with flags, description and optional coercion function and default value.
|
||||
* 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"
|
||||
*
|
||||
* @param flags the option flags.
|
||||
* @param description the option description. The description is printed when "--help" is used.
|
||||
* @param coerceFn (optional) specifies a callback function to coerce the option arg.
|
||||
* @param defaultValue (optional) specifies a default value.
|
||||
*/
|
||||
export function option(flags: string, description: string, coerceFn?: (value: string) => any, defaultValue?: any): Command;
|
||||
* Define option with flags, description and optional coercion function and default value.
|
||||
* 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"
|
||||
*
|
||||
* @param flags the option flags.
|
||||
* @param description the option description. The description is printed when "--help" is used.
|
||||
* @param coerceFn (optional) specifies a callback function to coerce the option arg.
|
||||
* @param defaultValue (optional) specifies a default value.
|
||||
*/
|
||||
export function option(flags:string, description:string, coerceFn?:(value:string) => any, defaultValue?:any):Command;
|
||||
|
||||
|
||||
/**
|
||||
* Sets the command version
|
||||
*/
|
||||
export function version(version: string): Command;
|
||||
* Sets the command version
|
||||
*/
|
||||
export function version(version:string):Command;
|
||||
|
||||
/**
|
||||
* Parse the arguments array and invokes the commands passing the parsed options.
|
||||
* @param argv the arguments array.
|
||||
*/
|
||||
export function parse(argv: string[]): Command;
|
||||
* Parse the arguments array and invokes the commands passing the parsed options.
|
||||
* @param argv the arguments array.
|
||||
*/
|
||||
export function parse(argv:string[]):Command;
|
||||
|
||||
/**
|
||||
* Gets or sets the command description.
|
||||
* @param description the new description for the command. When ommited this returns the current description, otherwise returns the current Command.
|
||||
*/
|
||||
export function description(description: string): Command;
|
||||
export function description(): string;
|
||||
* Gets or sets the command description.
|
||||
* @param description the new description for the command. When ommited this returns the current description, otherwise returns the current Command.
|
||||
*/
|
||||
export function description(description:string):Command;
|
||||
|
||||
export function description():string;
|
||||
|
||||
/**
|
||||
* Gets or sets the usage help string.
|
||||
*/
|
||||
export function usage(usage: string): Command;
|
||||
export function usage(): string;
|
||||
* Gets or sets the usage help string.
|
||||
*/
|
||||
export function usage(usage:string):Command;
|
||||
|
||||
export function usage():string;
|
||||
|
||||
/*
|
||||
* Prompt the user for a value, calling the callback function.
|
||||
*
|
||||
* Supports single-line and multi-line prompts.
|
||||
* To issue a single-line prompt simply add a whitespace
|
||||
* to the end of label, something like "name: ", whereas
|
||||
* for a multi-line prompt omit this "description:".
|
||||
* @param label the label string to be printed in console.
|
||||
* @param callback a callback function to handle the inputed string.
|
||||
*/
|
||||
export function prompt(label: string, callback: (value: string) => any): void;
|
||||
* Prompt the user for a value, calling the callback function.
|
||||
*
|
||||
* Supports single-line and multi-line prompts.
|
||||
* To issue a single-line prompt simply add a whitespace
|
||||
* to the end of label, something like "name: ", whereas
|
||||
* for a multi-line prompt omit this "description:".
|
||||
* @param label the label string to be printed in console.
|
||||
* @param callback a callback function to handle the inputed string.
|
||||
*/
|
||||
export function prompt(label:string, callback:(value:string) => any):void;
|
||||
|
||||
export function promptForNumber(label: string, callback: (value: number) => any): void;
|
||||
export function promptForDate(label: string, callback: (value: Date) => any): void;
|
||||
export function promptSingleLine(label: string, callback: (value: string) => any): void;
|
||||
export function promptMultiLine(label: string, callback: (value: string) => any): void;
|
||||
/**
|
||||
* Prompt for password with a label, a optional mask char and callback function.
|
||||
* The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.
|
||||
*/
|
||||
export function password(label: string, mask: string, callback: (value: string) => any): void;
|
||||
export function password(label: string, callback: (value: string) => any): void;
|
||||
export function promptForNumber(label:string, callback:(value:number) => any):void;
|
||||
|
||||
export function promptForDate(label:string, callback:(value:Date) => any):void;
|
||||
|
||||
export function promptSingleLine(label:string, callback:(value:string) => any):void;
|
||||
|
||||
export function promptMultiLine(label:string, callback:(value:string) => any):void;
|
||||
|
||||
/**
|
||||
* Prompts the user for a confirmation.
|
||||
*/
|
||||
export function confirm(label: string, callback: (flag: boolean) => any): void;
|
||||
* Prompt for password with a label, a optional mask char and callback function.
|
||||
* The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.
|
||||
*/
|
||||
export function password(label:string, mask:string, callback:(value:string) => any):void;
|
||||
|
||||
export function password(label:string, callback:(value:string) => any):void;
|
||||
|
||||
/**
|
||||
* Prompt for password with str, mask char and callback fn(val).
|
||||
* The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.
|
||||
*/
|
||||
export function choose(options: string[], callback: (idx: number) => any): void;
|
||||
export function choose(options: any[], callback: (idx: number) => any): void;
|
||||
* Prompts the user for a confirmation.
|
||||
*/
|
||||
export function confirm(label:string, callback:(flag:boolean) => any):void;
|
||||
|
||||
/**
|
||||
* Add command with the specified name. Returns a new instance of Command.
|
||||
*
|
||||
* The .action() callback is invoked when the
|
||||
* command name is specified via ARGV,
|
||||
* and the remaining arguments are applied to the
|
||||
* function for access.
|
||||
* Prompt for password with str, mask char and callback fn(val).
|
||||
* The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.
|
||||
*/
|
||||
export function choose(options:string[], callback:(idx:number) => any):void;
|
||||
|
||||
* When the name is "*" an un-matched command
|
||||
* will be passed as the first arg, followed by
|
||||
* the rest of ARGV remaining.
|
||||
*
|
||||
* @param name the name of the command. Pass "*" to trap un-matched commands.
|
||||
*/
|
||||
export function command(name: string): Command;
|
||||
export function choose(options:any[], callback:(idx:number) => any):void;
|
||||
|
||||
/**
|
||||
* Add command with the specified name. Returns a new instance of Command.
|
||||
*
|
||||
* The .action() callback is invoked when the
|
||||
* command name is specified via ARGV,
|
||||
* and the remaining arguments are applied to the
|
||||
* function for access.
|
||||
|
||||
* When the name is "*" an un-matched command
|
||||
* will be passed as the first arg, followed by
|
||||
* the rest of ARGV remaining.
|
||||
*
|
||||
* @param name the name of the command. Pass "*" to trap un-matched commands.
|
||||
*/
|
||||
export function command(name:string):Command;
|
||||
}
|
||||
Reference in New Issue
Block a user