UNPKG

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