UNPKG

3.8 kBTypeScriptView Raw
1import Command from '@oclif/command';
2import { OutputArgs, OutputFlags } from '@oclif/parser';
3import { ConfigAggregator, Logger, Org, SfdxError, SfdxProject } from '@salesforce/core';
4import { AnyJson, JsonMap, Optional } from '@salesforce/ts-types';
5import { flags as Flags, FlagsConfig } from './sfdxFlags';
6import { TableOptions, UX } from './ux';
7import { Deprecation } from './ux';
8export interface SfdxResult {
9 data?: AnyJson;
10 tableColumnData?: TableOptions;
11 display?: (this: Result) => void;
12}
13/**
14 * A class that handles command results and formatting. Use this class
15 * to override command display behavior or to get complex table formatting.
16 * For simple table formatting, use {@link SfdxCommand.tableColumnData} to
17 * define a string array of keys to use as table columns.
18 */
19export declare class Result implements SfdxResult {
20 data: AnyJson;
21 tableColumnData?: TableOptions;
22 ux: UX;
23 constructor(config?: SfdxResult);
24 display(): void;
25}
26/**
27 * Defines a varargs configuration. If set to true, there will be no
28 * validation and varargs will not be required. The validator function
29 * should throw an error if validation fails.
30 */
31export declare type VarargsConfig = {
32 required: boolean;
33 validator?: (name: string, value: string) => void;
34} | boolean;
35/**
36 * A base command that provides convenient access to common SFDX flags, a logger,
37 * CLI output formatting, scratch orgs, and devhubs. Extend this command and set
38 * various static properties and a flag configuration to add SFDX behavior.
39 *
40 * @extends @oclif/command
41 * @see https://github.com/oclif/command
42 */
43export declare abstract class SfdxCommand extends Command {
44 static readonly flags: Flags.Input<any>;
45 static readonly usage: string;
46 static getVarArgsConfig(): Partial<VarargsConfig> | undefined;
47 protected readonly statics: typeof SfdxCommand;
48 protected static supportsUsername: boolean;
49 protected static requiresUsername: boolean;
50 protected static supportsDevhubUsername: boolean;
51 protected static requiresDevhubUsername: boolean;
52 protected static requiresProject: boolean;
53 protected static deprecated?: Deprecation;
54 protected static tableColumnData: string[];
55 protected static flagsConfig: FlagsConfig;
56 protected static result: SfdxResult;
57 protected static varargs: VarargsConfig;
58 protected logger: Logger;
59 protected ux: UX;
60 protected configAggregator: ConfigAggregator;
61 protected org?: Org;
62 protected hubOrg?: Org;
63 protected project?: SfdxProject;
64 protected result: Result;
65 protected flags: OutputFlags<any>;
66 protected args: OutputArgs<any>;
67 protected varargs?: JsonMap;
68 private isJson;
69 _run<T>(): Promise<Optional<T>>;
70 abstract run(): Promise<any>;
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 * @returns {string[]} Returns decorated messages.
89 */
90 protected formatError(error: SfdxError): string[];
91 /**
92 * Initialize logger and ux for the command
93 */
94 protected initLoggerAndUx(): Promise<void>;
95}