UNPKG

4.33 kBTypeScriptView Raw
1import { Command } from '@oclif/core';
2import { Logger, Org, SfdxConfigAggregator, SfError, SfProject } from '@salesforce/core';
3import { AnyJson, JsonMap, Optional } from '@salesforce/ts-types';
4import { OutputArgs, OutputFlags } from '@oclif/core/lib/interfaces';
5import { flags as Flags, FlagsConfig } from './sfdxFlags';
6import { Deprecation, TableColumns, UX } from './ux';
7export interface SfdxResult {
8 data?: AnyJson;
9 tableColumnData?: TableColumns;
10 display?: (this: Result) => void;
11}
12/**
13 * A class that handles command results and formatting. Use this class
14 * to override command display behavior or to get complex table formatting.
15 * For simple table formatting, use {@link SfdxCommand.tableColumnData} to
16 * define a string array of keys to use as table columns.
17 */
18export declare class Result implements SfdxResult {
19 data: AnyJson;
20 tableColumnData?: TableColumns;
21 ux: UX;
22 constructor(config?: SfdxResult);
23 display(): void;
24}
25/**
26 * Defines a varargs configuration. If set to true, there will be no
27 * validation and varargs will not be required. The validator function
28 * should throw an error if validation fails.
29 */
30export declare type VarargsConfig = {
31 required: boolean;
32 validator?: (name: string, value: string) => void;
33} | boolean;
34/**
35 * A base command that provides convenient access to common SFDX flags, a logger,
36 * CLI output formatting, scratch orgs, and devhubs. Extend this command and set
37 * various static properties and a flag configuration to add SFDX behavior.
38 *
39 * @extends @oclif/command
40 * @see https://github.com/oclif/command
41 */
42export declare abstract class SfdxCommand extends Command {
43 protected get statics(): typeof SfdxCommand;
44 protected static supportsUsername: boolean;
45 protected static requiresUsername: boolean;
46 protected static supportsDevhubUsername: boolean;
47 protected static requiresDevhubUsername: boolean;
48 protected static requiresProject: boolean;
49 protected static deprecated?: Deprecation;
50 protected static tableColumnData: string[];
51 protected static flagsConfig: FlagsConfig;
52 protected static result: SfdxResult;
53 protected static varargs: VarargsConfig;
54 protected logger: Logger;
55 protected ux: UX;
56 protected configAggregator: SfdxConfigAggregator;
57 protected org?: Org;
58 protected hubOrg?: Org;
59 protected project?: SfProject;
60 protected result: Result;
61 protected flags: OutputFlags<any>;
62 protected args: OutputArgs;
63 protected varargs?: JsonMap;
64 /** event names to be registered for command specific hooks */
65 protected readonly lifecycleEventNames: string[];
66 private isJson;
67 static getVarArgsConfig(): Partial<VarargsConfig> | undefined;
68 _run<T>(): Promise<Optional<T>>;
69 protected assignProject(): Promise<void>;
70 protected assignOrg(): Promise<void>;
71 protected assignHubOrg(): Promise<void>;
72 protected shouldEmitHelp(): boolean;
73 protected init(): Promise<void>;
74 protected catch(err: any): Promise<void>;
75 protected finally(err: Optional<Error>): Promise<void>;
76 protected warnIfDeprecated(): void;
77 protected getJsonResultObject(result?: AnyJson, status?: number): {
78 status: number;
79 result: AnyJson;
80 };
81 protected parseVarargs(args?: string[]): JsonMap;
82 /**
83 * Format errors and actions for human consumption. Adds 'ERROR running <command name>',
84 * and outputs all errors in red. When there are actions, we add 'Try this:' in blue
85 * followed by each action in red on its own line.
86 *
87 * @returns {string[]} Returns decorated messages.
88 */
89 protected formatError(error: SfError): string[];
90 /**
91 * Initialize logger and ux for the command
92 */
93 protected initLoggerAndUx(): Promise<void>;
94 /**
95 * register events for command specific hooks
96 */
97 private hooksFromLifecycleEvent;
98 static get flags(): Flags.Input<any>;
99 static get usage(): string;
100 /**
101 * Actual command run code goes here.
102 *
103 * @returns {Promise<any>} Returns a promise
104 * @throws {Error | SfError} Throws an error. If the error is not an SfError, it will
105 * be wrapped in an SfError. If the error contains exitCode field, process.exitCode
106 * will set to it.
107 */
108 abstract run(): Promise<any>;
109}