UNPKG

4.39 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 *
36 * @deprecated Use SfCommand from `@salesforce/sf-plugins-core`
37 *
38 * A base command that provides convenient access to common SFDX flags, a logger,
39 * CLI output formatting, scratch orgs, and devhubs. Extend this command and set
40 * various static properties and a flag configuration to add SFDX behavior.
41 *
42 * @extends @oclif/command
43 * @see https://github.com/oclif/command
44 */
45export declare abstract class SfdxCommand extends Command {
46 protected static supportsUsername: boolean;
47 protected static requiresUsername: boolean;
48 protected static supportsDevhubUsername: boolean;
49 protected static requiresDevhubUsername: boolean;
50 protected static requiresProject: boolean;
51 protected static deprecated?: Deprecation;
52 protected static tableColumnData: string[];
53 protected static flagsConfig: FlagsConfig;
54 protected static result: SfdxResult;
55 protected static varargs: VarargsConfig;
56 protected logger: Logger;
57 protected ux: UX;
58 protected configAggregator: SfdxConfigAggregator;
59 protected org?: Org;
60 protected hubOrg?: Org;
61 protected project?: SfProject;
62 protected result: Result;
63 protected flags: OutputFlags<any>;
64 protected args: OutputArgs;
65 protected varargs?: JsonMap;
66 /** event names to be registered for command specific hooks */
67 protected readonly lifecycleEventNames: string[];
68 private isJson;
69 static get flags(): Flags.Input<any>;
70 static get usage(): string;
71 protected get statics(): typeof SfdxCommand;
72 static getVarArgsConfig(): Partial<VarargsConfig> | undefined;
73 _run<T>(): Promise<Optional<T>>;
74 protected assignProject(): Promise<void>;
75 protected assignOrg(): Promise<void>;
76 protected assignHubOrg(): Promise<void>;
77 protected shouldEmitHelp(): boolean;
78 protected init(): Promise<void>;
79 protected catch(err: any): Promise<void>;
80 protected finally(err: Optional<Error>): Promise<void>;
81 protected warnIfDeprecated(): void;
82 protected getJsonResultObject(result?: AnyJson, status?: number): {
83 status: number;
84 result: AnyJson;
85 };
86 protected parseVarargs(args?: string[]): JsonMap;
87 /**
88 * Format errors and actions for human consumption. Adds 'ERROR running <command name>',
89 * and outputs all errors in red. When there are actions, we add 'Try this:' in blue
90 * followed by each action in red on its own line.
91 *
92 * @returns {string[]} Returns decorated messages.
93 */
94 protected formatError(error: SfError): string[];
95 /**
96 * Initialize logger and ux for the command
97 */
98 protected initLoggerAndUx(): Promise<void>;
99 /**
100 * register events for command specific hooks
101 */
102 private hooksFromLifecycleEvent;
103 /**
104 * Actual command run code goes here.
105 *
106 * @returns {Promise<any>} Returns a promise
107 * @throws {Error | SfError} Throws an error. If the error is not an SfError, it will
108 * be wrapped in an SfError. If the error contains exitCode field, process.exitCode
109 * will set to it.
110 */
111 abstract run(): Promise<any>;
112}