UNPKG

11.4 kBTypeScriptView Raw
1/// <reference types="node" />
2import { URL } from 'url';
3import { Duration } from '@salesforce/kit';
4import { Omit, Optional } from '@salesforce/ts-types';
5import { BooleanFlag, EnumFlagOptions, Flag as OclifFlag, FlagInput, FlagOutput, OptionFlag } from '@oclif/core/lib/interfaces';
6import { Deprecation } from './ux';
7export declare namespace flags {
8 type Any<T> = Partial<OclifFlag<T>> & SfdxProperties;
9 type Array<T = string> = Option<T[]> & {
10 delimiter?: string;
11 };
12 type BaseBoolean<T> = Partial<BooleanFlag<T>>;
13 type Boolean<T> = BaseBoolean<T> & SfdxProperties;
14 type Bounds<T> = {
15 min?: T;
16 max?: T;
17 };
18 type Builtin = {
19 type: 'builtin';
20 } & Partial<SfdxProperties>;
21 type DateTime = Option<Date>;
22 type Deprecatable = {
23 deprecated?: Deprecation;
24 };
25 type Describable = {
26 description: string;
27 longDescription?: string;
28 };
29 type Discriminant = {
30 kind: Kind;
31 };
32 type Discriminated<T> = T & Discriminant;
33 type Enum<T> = EnumFlagOptions<T> & SfdxProperties;
34 type Kind = keyof typeof flags;
35 type Input<T extends FlagOutput> = FlagInput<T>;
36 type MappedArray<T> = Omit<flags.Array<T>, 'options'> & {
37 map: (val: string) => T;
38 options?: T[];
39 };
40 type Milliseconds = Option<Duration> & Bounds<Duration | number>;
41 type Minutes = Option<Duration> & Bounds<Duration | number>;
42 type Number = Option<number> & NumericBounds;
43 type NumericBounds = Bounds<number>;
44 type Option<T> = Partial<OptionFlag<T>> & SfdxProperties & Validatable;
45 type Output = FlagOutput;
46 type Seconds = Option<Duration> & Bounds<Duration | number>;
47 type SfdxProperties = Describable & Deprecatable;
48 type String = Option<string>;
49 type Url = Option<URL>;
50 type Validatable = {
51 validate?: string | RegExp | ((val: string) => boolean);
52 };
53}
54declare function buildBoolean<T = boolean>(options: flags.Boolean<T>): flags.Discriminated<flags.Boolean<T>>;
55declare function buildEnum<T>(options: flags.Enum<T>): flags.Discriminated<flags.Enum<T>>;
56declare function buildHelp(options: flags.BaseBoolean<boolean>): flags.Discriminated<flags.Boolean<void>>;
57declare function buildFilepath(options: flags.String): flags.Discriminated<flags.String>;
58declare function buildDirectory(options: flags.String): flags.Discriminated<flags.String>;
59declare function buildInteger(options: flags.Number): flags.Discriminated<flags.Number>;
60declare function buildOption<T>(options: {
61 parse: (val: string, ctx: unknown) => T;
62} & flags.Option<T>): flags.Discriminated<flags.Option<T>>;
63declare function buildString(options: flags.String): flags.Discriminated<flags.String>;
64declare function buildVersion(options?: flags.BaseBoolean<boolean>): flags.Discriminated<flags.Boolean<void>>;
65declare function buildArray(options: flags.Array<string>): flags.Discriminated<flags.Array<string>>;
66declare function buildArray<T>(options: flags.MappedArray<T>): flags.Discriminated<flags.Array<T>>;
67declare function buildDate(options: flags.DateTime): flags.Discriminated<flags.DateTime>;
68declare function buildDatetime(options: flags.DateTime): flags.Discriminated<flags.DateTime>;
69declare function buildEmail(options: flags.String): flags.Discriminated<flags.String>;
70declare function buildId(options: flags.String): flags.Discriminated<flags.String>;
71declare function buildMilliseconds(options: flags.Milliseconds): flags.Discriminated<flags.Milliseconds>;
72declare function buildMinutes(options: flags.Minutes): flags.Discriminated<flags.Minutes>;
73declare function buildNumber(options: flags.Number): flags.Discriminated<flags.Number>;
74declare function buildSeconds(options: flags.Seconds): flags.Discriminated<flags.Seconds>;
75declare function buildUrl(options: flags.Url): flags.Discriminated<flags.Url>;
76declare function buildBuiltin(options?: Partial<flags.Builtin>): flags.Builtin;
77export declare const flags: {
78 /**
79 * A flag type whose presence indicates a `true` boolean value. Produces false when not present.
80 */
81 boolean: typeof buildBoolean;
82 /**
83 * A flag type with a fixed enumeration of possible option values. Produces a validated string from the `options` list.
84 */
85 enum: typeof buildEnum;
86 /**
87 * A flag type useful for overriding the short `char` trigger for emitting CLI help. Emits help and exits the CLI.
88 */
89 help: typeof buildHelp;
90 /**
91 * A flag type that accepts basic integer values. For floats, binary, octal, and hex, see {@link flags.number}.
92 * Produces an integer `number`.
93 */
94 integer: typeof buildInteger;
95 /**
96 * A flag type for custom string processing. Accepts a `parse` function that converts a `string` value to a type `T`.
97 * Produces a type `T`.
98 */
99 option: typeof buildOption;
100 /**
101 * A flag type for returning a raw `string` value without further preprocessing. Produces a string.
102 */
103 string: typeof buildString;
104 /**
105 * A flag type for emitting CLI version information. Emits the CLI version and exits the CLI.
106 */
107 version: typeof buildVersion;
108 /**
109 * A flag type for valid file paths. Produces a validated string.
110 *
111 * **See** [@salesforce/core#sfdc.validatePathDoesNotContainInvalidChars](https://forcedotcom.github.io/sfdx-core/globals.html#sfdc), e.g. "this/is/my/path".
112 */
113 filepath: typeof buildFilepath;
114 /**
115 * A flag type for valid directory paths. Produces a validated string.
116 *
117 * **See** [@salesforce/core#sfdc.validatePathDoesNotContainInvalidChars](https://forcedotcom.github.io/sfdx-core/globals.html#sfdc), e.g. "this/is/my/path".
118 */
119 directory: typeof buildDirectory;
120 /**
121 * A flag type for a delimited list of strings with the delimiter defaulting to `,`, e.g., "one,two,three". Accepts
122 * an optional `delimiter` `string` and/or a custom `map` function for converting parsed `string` values into
123 * a type `T`. Produces a parsed (and possibly mapped) array of type `T` where `T` defaults to `string` if no
124 * custom `map` function was provided.
125 */
126 array: typeof buildArray;
127 /**
128 * A flag type for a valid date, e.g., "01-02-2000" or "01/02/2000 01:02:34". Produces a parsed `Date`.
129 */
130 date: typeof buildDate;
131 /**
132 * A flag type for a valid datetime, e.g., "01-02-2000" or "01/02/2000 01:02:34". Produces a parsed `Date`.
133 */
134 datetime: typeof buildDatetime;
135 /**
136 * A flag type for valid email addresses. Produces a validated string.
137 *
138 * **See** [@salesforce/core#sfdc.validateEmail](https://forcedotcom.github.io/sfdx-core/globals.html#sfdc), e.g., "me@my.org".
139 */
140 email: typeof buildEmail;
141 /**
142 * A flag type for valid Salesforce IDs. Produces a validated string.
143 *
144 * **See** [@salesforce/core#sfdc.validateSalesforceId](https://forcedotcom.github.io/sfdx-core/globals.html#sfdc), e.g., "00Dxxxxxxxxxxxx".
145 */
146 id: typeof buildId;
147 /**
148 * A flag type for a valid `Duration` in milliseconds, e.g., "5000".
149 */
150 milliseconds: typeof buildMilliseconds;
151 /**
152 * A flag type for a valid `Duration` in minutes, e.g., "2".
153 */
154 minutes: typeof buildMinutes;
155 /**
156 * A flag type for valid integer or floating point number, e.g., "42". Additionally supports binary, octal, and hex
157 * notation. Produces a parsed `number`.
158 */
159 number: typeof buildNumber;
160 /**
161 * A flag type for a valid `Duration` in seconds, e.g., "5".
162 */
163 seconds: typeof buildSeconds;
164 /**
165 * A flag type for a valid url, e.g., "http://www.salesforce.com". Produces a parsed `URL` instance.
166 */
167 url: typeof buildUrl;
168 /**
169 * Declares a flag definition to be one of the builtin types, for automatic configuration.
170 */
171 builtin: typeof buildBuiltin;
172};
173export declare const requiredBuiltinFlags: {
174 json(): flags.Discriminated<flags.Boolean<boolean>>;
175 loglevel(): flags.Discriminated<flags.Enum<string>>;
176};
177export declare const optionalBuiltinFlags: {
178 apiversion(opts?: flags.Builtin | undefined): flags.Discriminated<flags.String>;
179 concise(opts?: flags.Builtin | undefined): flags.Discriminated<flags.Boolean<boolean>>;
180 quiet(opts?: flags.Builtin | undefined): flags.Discriminated<flags.Boolean<boolean>>;
181 targetdevhubusername(opts?: flags.Builtin | undefined): flags.Discriminated<flags.String>;
182 targetusername(opts?: flags.Builtin | undefined): flags.Discriminated<flags.String>;
183 verbose(opts?: flags.Builtin | undefined): flags.Discriminated<flags.Boolean<boolean>>;
184};
185/**
186 * The configuration of flags for an {@link SfdxCommand} class, except for the following:
187 *
188 * * `json` and `loglevel` are configured automatically for all {@link SfdxCommand} classes.
189 * * `targetusername` is enabled using either `SfdxCommand.supportsUsername` or `SfdxCommand.requiresUsername`.
190 * * `targetdevhubusername` is enabled using either `SfdxCommand.supportsDevhubUsername` or `SfdxCommand.requiresDevhubUsername`.
191 *
192 * Additionally, `apiversion` is enabled automatically if any of the static `*Username` booleans are set, but may be
193 * configured here explicitly as well if those settings are not required.
194 *
195 * ```
196 * public static flagsConfig: FlagsConfig = {
197 * name: flags.string({ char: 'n', required: true, description: 'name of the resource to create' }),
198 * wait: flags.minutes({ description: 'number of minutes to wait for creation' }),
199 * notify: flags.url({ description: 'url to notify upon completion' })
200 * };
201 * ```
202 */
203export declare type FlagsConfig = {
204 [key: string]: Optional<flags.Boolean<unknown> | flags.Option<unknown> | flags.Builtin>;
205 /**
206 * Adds the `apiversion` built-in flag to allow for overriding the API
207 * version when executing the command.
208 */
209 apiversion?: flags.Builtin;
210 /**
211 * Adds the `concise` built-in flag to allow a command to support concise output,
212 * which is useful when the output can be overly verbose, such as test results.
213 * Note that this must be implemented by the command.
214 */
215 concise?: flags.Builtin;
216 /**
217 * Adds the `quiet` built-in flag to allow a command to completely suppress output.
218 * Note that this must be implemented by the command.
219 */
220 quiet?: flags.Builtin;
221 /**
222 * Adds the `verbose` built-in flag to allow a command to support verbose output,
223 * which is useful to display additional command results.
224 * Note that this must be implemented by the command.
225 */
226 verbose?: flags.Builtin;
227 targetdevhubusername?: never;
228 targetusername?: never;
229};
230/**
231 * Builds flags for a command given a configuration object. Supports the following use cases:
232 * 1. Enabling common SFDX flags. E.g., { verbose: true }
233 * 2. Defining typed flags. E.g., { myFlag: Flags.array({ char: '-a' }) }
234 * 3. Defining custom typed flags. E.g., { myFlag: Flags.custom({ parse: (val) => parseInt(val, 10) }) }
235 *
236 * @param {FlagsConfig} flagsConfig The configuration object for a flag. @see {@link FlagsConfig}
237 * @param options Extra configuration options.
238 * @returns {flags.Output} The flags for the command.
239 * @ignore
240 */
241export declare function buildSfdxFlags(flagsConfig: FlagsConfig, options: {
242 targetdevhubusername?: boolean;
243 targetusername?: boolean;
244}): flags.Output;
245export {};
246
\No newline at end of file