index.d.ts 11 KB

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