UNPKG

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