programs.d.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { MinimistArgs, Option, Options } from './options';
  2. /**
  3. * Dictionary that maps the command and the program.
  4. */
  5. export interface Programs {
  6. [cmd: string]: Program;
  7. }
  8. /**
  9. * A program has a command, a description, options, and a run method
  10. */
  11. export declare class Program {
  12. static MIN_SPACING: number;
  13. cmd: string;
  14. cmdDescription: string;
  15. options: Options;
  16. runMethod: Function;
  17. helpDescription: string;
  18. version: string;
  19. /**
  20. * Register a command and the description.
  21. * @param cmd The command.
  22. * @param cmdDescription The description of the command.
  23. * @returns The program for method chaining.
  24. */
  25. command(cmd: string, cmdDescription: string): Program;
  26. /**
  27. * Register a new option.
  28. * @param opt The option.
  29. * @param description The description of the option.
  30. * @param type The type of value expected: boolean, number, or string
  31. * @param defaultValue The option's default value.
  32. * @returns The program for method chaining.
  33. */
  34. option(opt: string, description: string, type: string, opt_defaultValue?: number | string | boolean): Program;
  35. /**
  36. * Adds an option to the program.
  37. * @param option The option.
  38. * @returns The program for method chaining.
  39. */
  40. addOption(option: Option): Program;
  41. /**
  42. * Registers a method that will be used to run the program.
  43. * @param runMethod The method that will be used to run the program.
  44. * @returns The program for method chaining.
  45. */
  46. action(runMethod: Function): Program;
  47. /**
  48. * Adds the value to the options and passes the updated options to the run
  49. * method.
  50. * @param args The arguments that will be parsed to run the method.
  51. */
  52. run(json: JSON): Promise<void>;
  53. private getValue_(key, json);
  54. /**
  55. * Prints the command with the description. The description will have spaces
  56. * between the cmd so that the starting position is "posDescription". If the
  57. * gap between the cmd and the description is less than MIN_SPACING or
  58. * posDescription is undefined, the spacing will be MIN_SPACING.
  59. *
  60. * @param opt_postDescription Starting position of the description.
  61. */
  62. printCmd(opt_posDescription?: number): void;
  63. /**
  64. * Prints the options with the option descriptions and default values.
  65. * The posDescription and posDefault is the starting position for the option
  66. * description. If extOptions are provided, check to see if we have already
  67. * printed those options. Also, once we print the option, add them to the extOptions.
  68. *
  69. * @param posDescription Position to start logging the description.
  70. * @param posDefault Position to start logging the default value.
  71. * @param opt_extOptions A collection of options that will be updated.
  72. */
  73. printOptions(posDescription: number, posDefault: number, opt_extOptions?: Options): void;
  74. /**
  75. * Assuming that the this program can run by itself, to print out the program's
  76. * help. Also assuming that the commands are called cmd-run and cmd-help.
  77. */
  78. printHelp(): void;
  79. posDescription(): number;
  80. posDefault(): number;
  81. lengthOf_(param: string): number;
  82. /**
  83. * Create a collection of options used by this program.
  84. * @returns The options used in the programs.
  85. */
  86. getOptions_(allOptions: Options): Options;
  87. /**
  88. * Get the options used by the program and create the minimist options
  89. * to ensure that minimist parses the values properly.
  90. * @returns The options for minimist.
  91. */
  92. getMinimistOptions(): MinimistArgs;
  93. }