UNPKG

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