@salesforce/command
Version:
Salesforce CLI base command class
113 lines (112 loc) • 4.39 kB
TypeScript
import { Command } from '@oclif/core';
import { Logger, Org, SfdxConfigAggregator, SfError, SfProject } from '@salesforce/core';
import { AnyJson, JsonMap, Optional } from '@salesforce/ts-types';
import { OutputArgs, OutputFlags } from '@oclif/core/lib/interfaces';
import { flags as Flags, FlagsConfig } from './sfdxFlags';
import { Deprecation, TableColumns, UX } from './ux';
export interface SfdxResult {
data?: AnyJson;
tableColumnData?: TableColumns;
display?: (this: Result) => void;
}
/**
* A class that handles command results and formatting. Use this class
* to override command display behavior or to get complex table formatting.
* For simple table formatting, use {@link SfdxCommand.tableColumnData} to
* define a string array of keys to use as table columns.
*/
export declare class Result implements SfdxResult {
data: AnyJson;
tableColumnData?: TableColumns;
ux: UX;
constructor(config?: SfdxResult);
display(): void;
}
/**
* Defines a varargs configuration. If set to true, there will be no
* validation and varargs will not be required. The validator function
* should throw an error if validation fails.
*/
export type VarargsConfig = {
required: boolean;
validator?: (name: string, value: string) => void;
} | boolean;
/**
*
* @deprecated Use SfCommand from `@salesforce/sf-plugins-core`
*
* A base command that provides convenient access to common SFDX flags, a logger,
* CLI output formatting, scratch orgs, and devhubs. Extend this command and set
* various static properties and a flag configuration to add SFDX behavior.
*
* @extends @oclif/command
* @see https://github.com/oclif/command
*/
export declare abstract class SfdxCommand extends Command {
protected static supportsUsername: boolean;
protected static requiresUsername: boolean;
protected static supportsDevhubUsername: boolean;
protected static requiresDevhubUsername: boolean;
protected static requiresProject: boolean;
protected static deprecated?: Deprecation;
protected static tableColumnData: string[];
protected static flagsConfig: FlagsConfig;
protected static result: SfdxResult;
protected static varargs: VarargsConfig;
protected logger: Logger;
protected ux: UX;
protected configAggregator: SfdxConfigAggregator;
protected org?: Org;
protected hubOrg?: Org;
protected project?: SfProject;
protected result: Result;
protected flags: OutputFlags<any>;
protected args: OutputArgs;
protected varargs?: JsonMap;
/** event names to be registered for command specific hooks */
protected readonly lifecycleEventNames: string[];
private isJson;
static get flags(): Flags.Input<any>;
static get usage(): string;
protected get statics(): typeof SfdxCommand;
static getVarArgsConfig(): Partial<VarargsConfig> | undefined;
_run<T>(): Promise<Optional<T>>;
protected assignProject(): Promise<void>;
protected assignOrg(): Promise<void>;
protected assignHubOrg(): Promise<void>;
protected shouldEmitHelp(): boolean;
protected init(): Promise<void>;
protected catch(err: any): Promise<void>;
protected finally(err: Optional<Error>): Promise<void>;
protected warnIfDeprecated(): void;
protected getJsonResultObject(result?: AnyJson, status?: number): {
status: number;
result: AnyJson;
};
protected parseVarargs(args?: string[]): JsonMap;
/**
* Format errors and actions for human consumption. Adds 'ERROR running <command name>',
* and outputs all errors in red. When there are actions, we add 'Try this:' in blue
* followed by each action in red on its own line.
*
* @returns {string[]} Returns decorated messages.
*/
protected formatError(error: SfError): string[];
/**
* Initialize logger and ux for the command
*/
protected initLoggerAndUx(): Promise<void>;
/**
* register events for command specific hooks
*/
private hooksFromLifecycleEvent;
/**
* Actual command run code goes here.
*
* @returns {Promise<any>} Returns a promise
* @throws {Error | SfError} Throws an error. If the error is not an SfError, it will
* be wrapped in an SfError. If the error contains exitCode field, process.exitCode
* will set to it.
*/
abstract run(): Promise<any>;
}