Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.d.ts 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. // Type definitions for commander
  2. // Original definitions by: Alan Agius <https://github.com/alan-agius4>, Marcelo Dezem <https://github.com/mdezem>, vvakame <https://github.com/vvakame>, Jules Randolph <https://github.com/sveinburne>
  3. declare namespace commander {
  4. interface CommanderError extends Error {
  5. code: string;
  6. exitCode: number;
  7. message: string;
  8. nestedError?: string;
  9. }
  10. type CommanderErrorConstructor = new (exitCode: number, code: string, message: string) => CommanderError;
  11. interface Option {
  12. flags: string;
  13. required: boolean; // A value must be supplied when the option is specified.
  14. optional: boolean; // A value is optional when the option is specified.
  15. mandatory: boolean; // The option must have a value after parsing, which usually means it must be specified on command line.
  16. bool: boolean;
  17. short?: string;
  18. long: string;
  19. description: string;
  20. }
  21. type OptionConstructor = new (flags: string, description?: string) => Option;
  22. interface ParseOptions {
  23. from: 'node' | 'electron' | 'user';
  24. }
  25. interface Command {
  26. [key: string]: any; // options as properties
  27. args: string[];
  28. commands: Command[];
  29. /**
  30. * Set the program version to `str`.
  31. *
  32. * This method auto-registers the "-V, --version" flag
  33. * which will print the version number when passed.
  34. *
  35. * You can optionally supply the flags and description to override the defaults.
  36. */
  37. version(str: string, flags?: string, description?: string): this;
  38. /**
  39. * Define a command, implemented using an action handler.
  40. *
  41. * @remarks
  42. * The command description is supplied using `.description`, not as a parameter to `.command`.
  43. *
  44. * @example
  45. * ```ts
  46. * program
  47. * .command('clone <source> [destination]')
  48. * .description('clone a repository into a newly created directory')
  49. * .action((source, destination) => {
  50. * console.log('clone command called');
  51. * });
  52. * ```
  53. *
  54. * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
  55. * @param opts - configuration options
  56. * @returns new command
  57. */
  58. command(nameAndArgs: string, opts?: CommandOptions): ReturnType<this['createCommand']>;
  59. /**
  60. * Define a command, implemented in a separate executable file.
  61. *
  62. * @remarks
  63. * The command description is supplied as the second parameter to `.command`.
  64. *
  65. * @example
  66. * ```ts
  67. * program
  68. * .command('start <service>', 'start named service')
  69. * .command('stop [service]', 'stop named serice, or all if no name supplied');
  70. * ```
  71. *
  72. * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
  73. * @param description - description of executable command
  74. * @param opts - configuration options
  75. * @returns `this` command for chaining
  76. */
  77. command(nameAndArgs: string, description: string, opts?: commander.ExecutableCommandOptions): this;
  78. /**
  79. * Factory routine to create a new unattached command.
  80. *
  81. * See .command() for creating an attached subcommand, which uses this routine to
  82. * create the command. You can override createCommand to customise subcommands.
  83. */
  84. createCommand(name?: string): Command;
  85. /**
  86. * Add a prepared subcommand.
  87. *
  88. * See .command() for creating an attached subcommand which inherits settings from its parent.
  89. *
  90. * @returns `this` command for chaining
  91. */
  92. addCommand(cmd: Command, opts?: CommandOptions): this;
  93. /**
  94. * Define argument syntax for command.
  95. *
  96. * @returns `this` command for chaining
  97. */
  98. arguments(desc: string): this;
  99. /**
  100. * Register callback to use as replacement for calling process.exit.
  101. */
  102. exitOverride(callback?: (err: CommanderError) => never|void): this;
  103. /**
  104. * Register callback `fn` for the command.
  105. *
  106. * @example
  107. * program
  108. * .command('help')
  109. * .description('display verbose help')
  110. * .action(function() {
  111. * // output help here
  112. * });
  113. *
  114. * @returns `this` command for chaining
  115. */
  116. action(fn: (...args: any[]) => void | Promise<void>): this;
  117. /**
  118. * Define option with `flags`, `description` and optional
  119. * coercion `fn`.
  120. *
  121. * The `flags` string should contain both the short and long flags,
  122. * separated by comma, a pipe or space. The following are all valid
  123. * all will output this way when `--help` is used.
  124. *
  125. * "-p, --pepper"
  126. * "-p|--pepper"
  127. * "-p --pepper"
  128. *
  129. * @example
  130. * // simple boolean defaulting to false
  131. * program.option('-p, --pepper', 'add pepper');
  132. *
  133. * --pepper
  134. * program.pepper
  135. * // => Boolean
  136. *
  137. * // simple boolean defaulting to true
  138. * program.option('-C, --no-cheese', 'remove cheese');
  139. *
  140. * program.cheese
  141. * // => true
  142. *
  143. * --no-cheese
  144. * program.cheese
  145. * // => false
  146. *
  147. * // required argument
  148. * program.option('-C, --chdir <path>', 'change the working directory');
  149. *
  150. * --chdir /tmp
  151. * program.chdir
  152. * // => "/tmp"
  153. *
  154. * // optional argument
  155. * program.option('-c, --cheese [type]', 'add cheese [marble]');
  156. *
  157. * @returns `this` command for chaining
  158. */
  159. option(flags: string, description?: string, defaultValue?: string | boolean): this;
  160. option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
  161. option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
  162. /**
  163. * Define a required option, which must have a value after parsing. This usually means
  164. * the option must be specified on the command line. (Otherwise the same as .option().)
  165. *
  166. * The `flags` string should contain both the short and long flags, separated by comma, a pipe or space.
  167. */
  168. requiredOption(flags: string, description?: string, defaultValue?: string | boolean): this;
  169. requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
  170. requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
  171. /**
  172. * Whether to store option values as properties on command object,
  173. * or store separately (specify false). In both cases the option values can be accessed using .opts().
  174. *
  175. * @returns `this` command for chaining
  176. */
  177. storeOptionsAsProperties(value?: boolean): this;
  178. /**
  179. * Whether to pass command to action handler,
  180. * or just the options (specify false).
  181. *
  182. * @returns `this` command for chaining
  183. */
  184. passCommandToAction(value?: boolean): this;
  185. /**
  186. * Allow unknown options on the command line.
  187. *
  188. * @param [arg] if `true` or omitted, no error will be thrown for unknown options.
  189. * @returns `this` command for chaining
  190. */
  191. allowUnknownOption(arg?: boolean): this;
  192. /**
  193. * Parse `argv`, setting options and invoking commands when defined.
  194. *
  195. * The default expectation is that the arguments are from node and have the application as argv[0]
  196. * and the script being run in argv[1], with user parameters after that.
  197. *
  198. * Examples:
  199. *
  200. * program.parse(process.argv);
  201. * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
  202. * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
  203. *
  204. * @returns `this` command for chaining
  205. */
  206. parse(argv?: string[], options?: ParseOptions): this;
  207. /**
  208. * Parse `argv`, setting options and invoking commands when defined.
  209. *
  210. * Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
  211. *
  212. * The default expectation is that the arguments are from node and have the application as argv[0]
  213. * and the script being run in argv[1], with user parameters after that.
  214. *
  215. * Examples:
  216. *
  217. * program.parseAsync(process.argv);
  218. * program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
  219. * program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
  220. *
  221. * @returns Promise
  222. */
  223. parseAsync(argv?: string[], options?: ParseOptions): Promise<this>;
  224. /**
  225. * Parse options from `argv` removing known options,
  226. * and return argv split into operands and unknown arguments.
  227. *
  228. * @example
  229. * argv => operands, unknown
  230. * --known kkk op => [op], []
  231. * op --known kkk => [op], []
  232. * sub --unknown uuu op => [sub], [--unknown uuu op]
  233. * sub -- --unknown uuu op => [sub --unknown uuu op], []
  234. */
  235. parseOptions(argv: string[]): commander.ParseOptionsResult;
  236. /**
  237. * Return an object containing options as key-value pairs
  238. */
  239. opts(): { [key: string]: any };
  240. /**
  241. * Set the description.
  242. *
  243. * @returns `this` command for chaining
  244. */
  245. description(str: string, argsDescription?: {[argName: string]: string}): this;
  246. /**
  247. * Get the description.
  248. */
  249. description(): string;
  250. /**
  251. * Set an alias for the command.
  252. *
  253. * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
  254. *
  255. * @returns `this` command for chaining
  256. */
  257. alias(alias: string): this;
  258. /**
  259. * Get alias for the command.
  260. */
  261. alias(): string;
  262. /**
  263. * Set aliases for the command.
  264. *
  265. * Only the first alias is shown in the auto-generated help.
  266. *
  267. * @returns `this` command for chaining
  268. */
  269. aliases(aliases: string[]): this;
  270. /**
  271. * Get aliases for the command.
  272. */
  273. aliases(): string[];
  274. /**
  275. * Set the command usage.
  276. *
  277. * @returns `this` command for chaining
  278. */
  279. usage(str: string): this;
  280. /**
  281. * Get the command usage.
  282. */
  283. usage(): string;
  284. /**
  285. * Set the name of the command.
  286. *
  287. * @returns `this` command for chaining
  288. */
  289. name(str: string): this;
  290. /**
  291. * Get the name of the command.
  292. */
  293. name(): string;
  294. /**
  295. * Output help information for this command.
  296. *
  297. * When listener(s) are available for the helpLongFlag
  298. * those callbacks are invoked.
  299. */
  300. outputHelp(cb?: (str: string) => string): void;
  301. /**
  302. * Return command help documentation.
  303. */
  304. helpInformation(): string;
  305. /**
  306. * You can pass in flags and a description to override the help
  307. * flags and help description for your command.
  308. */
  309. helpOption(flags?: string, description?: string): this;
  310. /**
  311. * Output help information and exit.
  312. */
  313. help(cb?: (str: string) => string): never;
  314. /**
  315. * Add a listener (callback) for when events occur. (Implemented using EventEmitter.)
  316. *
  317. * @example
  318. * program
  319. * .on('--help', () -> {
  320. * console.log('See web site for more information.');
  321. * });
  322. */
  323. on(event: string | symbol, listener: (...args: any[]) => void): this;
  324. }
  325. type CommandConstructor = new (name?: string) => Command;
  326. interface CommandOptions {
  327. noHelp?: boolean; // old name for hidden
  328. hidden?: boolean;
  329. isDefault?: boolean;
  330. }
  331. interface ExecutableCommandOptions extends CommandOptions {
  332. executableFile?: string;
  333. }
  334. interface ParseOptionsResult {
  335. operands: string[];
  336. unknown: string[];
  337. }
  338. interface CommanderStatic extends Command {
  339. program: Command;
  340. Command: CommandConstructor;
  341. Option: OptionConstructor;
  342. CommanderError: CommanderErrorConstructor;
  343. }
  344. }
  345. // Declaring namespace AND global
  346. // eslint-disable-next-line no-redeclare
  347. declare const commander: commander.CommanderStatic;
  348. export = commander;