UNPKG

4.32 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 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 static supportsUsername: boolean;
44 protected static requiresUsername: boolean;
45 protected static supportsDevhubUsername: boolean;
46 protected static requiresDevhubUsername: boolean;
47 protected static requiresProject: boolean;
48 protected static deprecated?: Deprecation;
49 protected static tableColumnData: string[];
50 protected static flagsConfig: FlagsConfig;
51 protected static result: SfdxResult;
52 protected static varargs: VarargsConfig;
53 protected logger: Logger;
54 protected ux: UX;
55 protected configAggregator: SfdxConfigAggregator;
56 protected org?: Org;
57 protected hubOrg?: Org;
58 protected project?: SfProject;
59 protected result: Result;
60 protected flags: OutputFlags<any>;
61 protected args: OutputArgs;
62 protected varargs?: JsonMap;
63 /** event names to be registered for command specific hooks */
64 protected readonly lifecycleEventNames: string[];
65 private isJson;
66 static get flags(): Flags.Input<any>;
67 static get usage(): string;
68 protected get statics(): typeof SfdxCommand;
69 static getVarArgsConfig(): Partial<VarargsConfig> | undefined;
70 _run<T>(): Promise<Optional<T>>;
71 protected assignProject(): Promise<void>;
72 protected assignOrg(): Promise<void>;
73 protected assignHubOrg(): Promise<void>;
74 protected shouldEmitHelp(): boolean;
75 protected init(): Promise<void>;
76 protected catch(err: any): Promise<void>;
77 protected finally(err: Optional<Error>): Promise<void>;
78 protected warnIfDeprecated(): void;
79 protected getJsonResultObject(result?: AnyJson, status?: number): {
80 status: number;
81 result: AnyJson;
82 };
83 protected parseVarargs(args?: string[]): JsonMap;
84 /**
85 * Format errors and actions for human consumption. Adds 'ERROR running <command name>',
86 * and outputs all errors in red. When there are actions, we add 'Try this:' in blue
87 * followed by each action in red on its own line.
88 *
89 * @returns {string[]} Returns decorated messages.
90 */
91 protected formatError(error: SfError): string[];
92 /**
93 * Initialize logger and ux for the command
94 */
95 protected initLoggerAndUx(): Promise<void>;
96 /**
97 * register events for command specific hooks
98 */
99 private hooksFromLifecycleEvent;
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}