interface.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /**
  2. * @license
  3. * Copyright Google Inc. All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { analytics, json, logging } from '@angular-devkit/core';
  9. /**
  10. * Value type of arguments.
  11. */
  12. export declare type Value = number | string | boolean | (number | string | boolean)[];
  13. /**
  14. * An object representing parsed arguments from the command line.
  15. */
  16. export interface Arguments {
  17. [argName: string]: Value | undefined;
  18. /**
  19. * Extra arguments that were not parsed. Will be omitted if all arguments were parsed.
  20. */
  21. '--'?: string[];
  22. }
  23. /**
  24. * The base interface for Command, understood by the command runner.
  25. */
  26. export interface CommandInterface<T extends Arguments = Arguments> {
  27. printHelp(options: T): Promise<number>;
  28. printJsonHelp(options: T): Promise<number>;
  29. validateAndRun(options: T): Promise<number>;
  30. }
  31. /**
  32. * Command constructor.
  33. */
  34. export interface CommandConstructor {
  35. new (context: CommandContext, description: CommandDescription, logger: logging.Logger): CommandInterface;
  36. }
  37. /**
  38. * A CLI workspace information.
  39. */
  40. export interface CommandWorkspace {
  41. root: string;
  42. configFile?: string;
  43. }
  44. /**
  45. * A command runner context.
  46. */
  47. export interface CommandContext {
  48. workspace: CommandWorkspace;
  49. analytics?: analytics.Analytics;
  50. }
  51. /**
  52. * Value types of an Option.
  53. */
  54. export declare enum OptionType {
  55. Any = "any",
  56. Array = "array",
  57. Boolean = "boolean",
  58. Number = "number",
  59. String = "string"
  60. }
  61. /**
  62. * An option description. This is exposed when using `ng --help=json`.
  63. */
  64. export interface Option {
  65. /**
  66. * The name of the option.
  67. */
  68. name: string;
  69. /**
  70. * A short description of the option.
  71. */
  72. description: string;
  73. /**
  74. * The type of option value. If multiple types exist, this type will be the first one, and the
  75. * types array will contain all types accepted.
  76. */
  77. type: OptionType;
  78. /**
  79. * {@see type}
  80. */
  81. types?: OptionType[];
  82. /**
  83. * If this field is set, only values contained in this field are valid. This array can be mixed
  84. * types (strings, numbers, boolean). For example, if this field is "enum: ['hello', true]",
  85. * then "type" will be either string or boolean, types will be at least both, and the values
  86. * accepted will only be either 'hello' or true (not false or any other string).
  87. * This mean that prefixing with `no-` will not work on this field.
  88. */
  89. enum?: Value[];
  90. /**
  91. * If this option maps to a subcommand in the parent command, will contain all the subcommands
  92. * supported. There is a maximum of 1 subcommand Option per command, and the type of this
  93. * option will always be "string" (no other types). The value of this option will map into
  94. * this map and return the extra information.
  95. */
  96. subcommands?: {
  97. [name: string]: SubCommandDescription;
  98. };
  99. /**
  100. * Aliases supported by this option.
  101. */
  102. aliases: string[];
  103. /**
  104. * Whether this option is required or not.
  105. */
  106. required?: boolean;
  107. /**
  108. * Format field of this option.
  109. */
  110. format?: string;
  111. /**
  112. * Whether this option should be hidden from the help output. It will still show up in JSON help.
  113. */
  114. hidden?: boolean;
  115. /**
  116. * Default value of this option.
  117. */
  118. default?: string | number | boolean;
  119. /**
  120. * If this option can be used as an argument, the position of the argument. Otherwise omitted.
  121. */
  122. positional?: number;
  123. /**
  124. * Deprecation. If this flag is not false a warning will be shown on the console. Either `true`
  125. * or a string to show the user as a notice.
  126. */
  127. deprecated?: boolean | string;
  128. /**
  129. * Smart default object.
  130. */
  131. $default?: OptionSmartDefault;
  132. /**
  133. * Whether or not to report this option to the Angular Team, and which custom field to use.
  134. * If this is falsey, do not report this option.
  135. */
  136. userAnalytics?: number;
  137. }
  138. /**
  139. * Scope of the command.
  140. */
  141. export declare enum CommandScope {
  142. InProject = "in",
  143. OutProject = "out",
  144. Everywhere = "all",
  145. Default = "in"
  146. }
  147. /**
  148. * A description of a command and its options.
  149. */
  150. export interface SubCommandDescription {
  151. /**
  152. * The name of the subcommand.
  153. */
  154. name: string;
  155. /**
  156. * Short description (1-2 lines) of this sub command.
  157. */
  158. description: string;
  159. /**
  160. * A long description of the sub command, in Markdown format.
  161. */
  162. longDescription?: string;
  163. /**
  164. * Additional notes about usage of this sub command, in Markdown format.
  165. */
  166. usageNotes?: string;
  167. /**
  168. * List of all supported options.
  169. */
  170. options: Option[];
  171. /**
  172. * Aliases supported for this sub command.
  173. */
  174. aliases: string[];
  175. }
  176. /**
  177. * A description of a command, its metadata.
  178. */
  179. export interface CommandDescription extends SubCommandDescription {
  180. /**
  181. * Scope of the command, whether it can be executed in a project, outside of a project or
  182. * anywhere.
  183. */
  184. scope: CommandScope;
  185. /**
  186. * Whether this command should be hidden from a list of all commands.
  187. */
  188. hidden: boolean;
  189. /**
  190. * The constructor of the command, which should be extending the abstract Command<> class.
  191. */
  192. impl: CommandConstructor;
  193. }
  194. export interface OptionSmartDefault {
  195. $source: string;
  196. [key: string]: json.JsonValue;
  197. }
  198. export interface CommandDescriptionMap {
  199. [key: string]: CommandDescription;
  200. }