index.d.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. // Generated by typings
  2. // Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/commander/commander.d.ts
  3. // Type definitions for commanderjs 2.3.0
  4. // Project: https://github.com/visionmedia/commander.js
  5. // Definitions by: Marcelo Dezem <http://github.com/mdezem>, vvakame <http://github.com/vvakame>
  6. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  7. declare namespace commander {
  8. interface ICommandStatic {
  9. /**
  10. * Initialize a new `Command`.
  11. *
  12. * @param {String} name
  13. * @api public
  14. */
  15. new (name?:string):ICommand;
  16. }
  17. interface ICommand extends NodeJS.EventEmitter {
  18. args: string[];
  19. _args: { required:boolean; name: string; }[];
  20. /**
  21. * Add command `name`.
  22. *
  23. * The `.action()` callback is invoked when the
  24. * command `name` is specified via __ARGV__,
  25. * and the remaining arguments are applied to the
  26. * function for access.
  27. *
  28. * When the `name` is "*" an un-matched command
  29. * will be passed as the first arg, followed by
  30. * the rest of __ARGV__ remaining.
  31. *
  32. * Examples:
  33. *
  34. * program
  35. * .version('0.0.1')
  36. * .option('-C, --chdir <path>', 'change the working directory')
  37. * .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
  38. * .option('-T, --no-tests', 'ignore test hook')
  39. *
  40. * program
  41. * .command('setup')
  42. * .description('run remote setup commands')
  43. * .action(function(){
  44. * console.log('setup');
  45. * });
  46. *
  47. * program
  48. * .command('exec <cmd>')
  49. * .description('run the given remote command')
  50. * .action(function(cmd){
  51. * console.log('exec "%s"', cmd);
  52. * });
  53. *
  54. * program
  55. * .command('*')
  56. * .description('deploy the given env')
  57. * .action(function(env){
  58. * console.log('deploying "%s"', env);
  59. * });
  60. *
  61. * program.parse(process.argv);
  62. *
  63. * @param {String} name
  64. * @param {String} [desc]
  65. * @param {Mixed} [opts]
  66. * @return {Command} the new command
  67. * @api public
  68. */
  69. command(name:string, desc?:string, opts?: any):ICommand;
  70. /**
  71. * Add an implicit `help [cmd]` subcommand
  72. * which invokes `--help` for the given command.
  73. *
  74. * @api private
  75. */
  76. addImplicitHelpCommand():void;
  77. /**
  78. * Parse expected `args`.
  79. *
  80. * For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.
  81. *
  82. * @param {Array} args
  83. * @return {Command} for chaining
  84. * @api public
  85. */
  86. parseExpectedArgs(args:string[]):ICommand;
  87. /**
  88. * Register callback `fn` for the command.
  89. *
  90. * Examples:
  91. *
  92. * program
  93. * .command('help')
  94. * .description('display verbose help')
  95. * .action(function(){
  96. * // output help here
  97. * });
  98. *
  99. * @param {Function} fn
  100. * @return {Command} for chaining
  101. * @api public
  102. */
  103. action(fn:(...args:any[])=>void):ICommand;
  104. /**
  105. * Define option with `flags`, `description` and optional
  106. * coercion `fn`.
  107. *
  108. * The `flags` string should contain both the short and long flags,
  109. * separated by comma, a pipe or space. The following are all valid
  110. * all will output this way when `--help` is used.
  111. *
  112. * "-p, --pepper"
  113. * "-p|--pepper"
  114. * "-p --pepper"
  115. *
  116. * Examples:
  117. *
  118. * // simple boolean defaulting to false
  119. * program.option('-p, --pepper', 'add pepper');
  120. *
  121. * --pepper
  122. * program.pepper
  123. * // => Boolean
  124. *
  125. * // simple boolean defaulting to true
  126. * program.option('-C, --no-cheese', 'remove cheese');
  127. *
  128. * program.cheese
  129. * // => true
  130. *
  131. * --no-cheese
  132. * program.cheese
  133. * // => false
  134. *
  135. * // required argument
  136. * program.option('-C, --chdir <path>', 'change the working directory');
  137. *
  138. * --chdir /tmp
  139. * program.chdir
  140. * // => "/tmp"
  141. *
  142. * // optional argument
  143. * program.option('-c, --cheese [type]', 'add cheese [marble]');
  144. *
  145. * @param {String} flags
  146. * @param {String} description
  147. * @param {Function|Mixed} fn or default
  148. * @param {Mixed} defaultValue
  149. * @return {Command} for chaining
  150. * @api public
  151. */
  152. option(flags:string, description?:string, fn?:((arg1:any, arg2:any)=>void)|RegExp, defaultValue?:any):ICommand;
  153. option(flags:string, description?:string, defaultValue?:any):ICommand;
  154. /**
  155. * Allow unknown options on the command line.
  156. *
  157. * @param {Boolean} arg if `true` or omitted, no error will be thrown
  158. * for unknown options.
  159. * @api public
  160. */
  161. allowUnknownOption(arg?: boolean):ICommand;
  162. /**
  163. * Parse `argv`, settings options and invoking commands when defined.
  164. *
  165. * @param {Array} argv
  166. * @return {Command} for chaining
  167. * @api public
  168. */
  169. parse(argv:string[]):ICommand;
  170. /**
  171. * Execute a sub-command executable.
  172. *
  173. * @param {Array} argv
  174. * @param {Array} args
  175. * @param {Array} unknown
  176. * @api private
  177. */
  178. executeSubCommand(argv:string[], args:string[], unknown:string[]):any; /* child_process.ChildProcess */
  179. /**
  180. * Normalize `args`, splitting joined short flags. For example
  181. * the arg "-abc" is equivalent to "-a -b -c".
  182. * This also normalizes equal sign and splits "--abc=def" into "--abc def".
  183. *
  184. * @param {Array} args
  185. * @return {Array}
  186. * @api private
  187. */
  188. normalize(args:string[]):string[];
  189. /**
  190. * Parse command `args`.
  191. *
  192. * When listener(s) are available those
  193. * callbacks are invoked, otherwise the "*"
  194. * event is emitted and those actions are invoked.
  195. *
  196. * @param {Array} args
  197. * @return {Command} for chaining
  198. * @api private
  199. */
  200. parseArgs(args:string[], unknown:string[]):ICommand;
  201. /**
  202. * Return an option matching `arg` if any.
  203. *
  204. * @param {String} arg
  205. * @return {Option}
  206. * @api private
  207. */
  208. optionFor(arg:string):IOption;
  209. /**
  210. * Parse options from `argv` returning `argv`
  211. * void of these options.
  212. *
  213. * @param {Array} argv
  214. * @return {Array}
  215. * @api public
  216. */
  217. parseOptions(argv:string[]): {args:string[]; unknown:string[];};
  218. /**
  219. * Return an object containing options as key-value pairs
  220. *
  221. * @return {Object}
  222. * @api public
  223. */
  224. opts():any;
  225. /**
  226. * Argument `name` is missing.
  227. *
  228. * @param {String} name
  229. * @api private
  230. */
  231. missingArgument(name:string):void;
  232. /**
  233. * `Option` is missing an argument, but received `flag` or nothing.
  234. *
  235. * @param {String} option
  236. * @param {String} flag
  237. * @api private
  238. */
  239. optionMissingArgument(option:{flags:string;}, flag?:string):void;
  240. /**
  241. * Unknown option `flag`.
  242. *
  243. * @param {String} flag
  244. * @api private
  245. */
  246. unknownOption(flag:string):void;
  247. /**
  248. * Set the program version to `str`.
  249. *
  250. * This method auto-registers the "-V, --version" flag
  251. * which will print the version number when passed.
  252. *
  253. * @param {String} str
  254. * @param {String} flags
  255. * @return {Command} for chaining
  256. * @api public
  257. */
  258. version(str:string, flags?:string):ICommand;
  259. /**
  260. * Set the description to `str`.
  261. *
  262. * @param {String} str
  263. * @return {String|Command}
  264. * @api public
  265. */
  266. description(str:string):ICommand;
  267. description():string;
  268. /**
  269. * Set an alias for the command
  270. *
  271. * @param {String} alias
  272. * @return {String|Command}
  273. * @api public
  274. */
  275. alias(alias:string):ICommand;
  276. alias():string;
  277. /**
  278. * Set / get the command usage `str`.
  279. *
  280. * @param {String} str
  281. * @return {String|Command}
  282. * @api public
  283. */
  284. usage(str:string):ICommand;
  285. usage():string;
  286. /**
  287. * Get the name of the command
  288. *
  289. * @param {String} name
  290. * @return {String|Command}
  291. * @api public
  292. */
  293. name():string;
  294. /**
  295. * Return the largest option length.
  296. *
  297. * @return {Number}
  298. * @api private
  299. */
  300. largestOptionLength():number;
  301. /**
  302. * Return help for options.
  303. *
  304. * @return {String}
  305. * @api private
  306. */
  307. optionHelp():string;
  308. /**
  309. * Return command help documentation.
  310. *
  311. * @return {String}
  312. * @api private
  313. */
  314. commandHelp():string;
  315. /**
  316. * Return program help documentation.
  317. *
  318. * @return {String}
  319. * @api private
  320. */
  321. helpInformation():string;
  322. /**
  323. * Output help information for this command
  324. *
  325. * @api public
  326. */
  327. outputHelp():void;
  328. /**
  329. * Output help information and exit.
  330. *
  331. * @api public
  332. */
  333. help():void;
  334. }
  335. interface IOptionStatic {
  336. /**
  337. * Initialize a new `Option` with the given `flags` and `description`.
  338. *
  339. * @param {String} flags
  340. * @param {String} description
  341. * @api public
  342. */
  343. new (flags:string, description?:string):IOption;
  344. }
  345. interface IOption {
  346. flags:string;
  347. required:boolean;
  348. optional:boolean;
  349. bool:boolean;
  350. short?:string;
  351. long:string;
  352. description:string;
  353. /**
  354. * Return option name.
  355. *
  356. * @return {String}
  357. * @api private
  358. */
  359. name():string;
  360. /**
  361. * Check if `arg` matches the short or long flag.
  362. *
  363. * @param {String} arg
  364. * @return {Boolean}
  365. * @api private
  366. */
  367. is(arg:string):boolean;
  368. }
  369. interface IExportedCommand extends ICommand {
  370. Command: commander.ICommandStatic;
  371. Option: commander.IOptionStatic;
  372. }
  373. }
  374. declare module "commander" {
  375. var _tmp:commander.IExportedCommand;
  376. export = _tmp;
  377. }