@salesforce/command
- Version 5.3.9
- Published
- 169 kB
- 6 dependencies
- BSD-3-Clause license
Install
npm i @salesforce/command
yarn add @salesforce/command
pnpm add @salesforce/command
Overview
Salesforce CLI base command class
Index
Variables
Classes
SfdxCommand
- args
- assignHubOrg()
- assignOrg()
- assignProject()
- catch()
- configAggregator
- deprecated
- finally()
- flags
- flags
- flagsConfig
- formatError()
- getJsonResultObject()
- getVarArgsConfig()
- hubOrg
- init()
- initLoggerAndUx()
- lifecycleEventNames
- logger
- org
- parseVarargs()
- project
- requiresDevhubUsername
- requiresProject
- requiresUsername
- result
- result
- run()
- shouldEmitHelp()
- statics
- supportsDevhubUsername
- supportsUsername
- tableColumnData
- usage
- ux
- varargs
- varargs
- warnIfDeprecated()
Interfaces
Type Aliases
Namespaces
Variables
variable flags
const flags: { boolean: typeof buildBoolean; enum: typeof buildEnum; help: typeof buildHelp; integer: typeof buildInteger; option: typeof buildOption; string: typeof buildString; version: typeof buildVersion; filepath: typeof buildFilepath; directory: typeof buildDirectory; array: typeof buildArray; date: typeof buildDate; datetime: typeof buildDatetime; email: typeof buildEmail; id: typeof buildId; milliseconds: typeof buildMilliseconds; minutes: typeof buildMinutes; number: typeof buildNumber; seconds: typeof buildSeconds; url: typeof buildUrl; builtin: typeof buildBuiltin;};
Classes
class Result
class Result implements SfdxResult {}
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 SfdxCommand.tableColumnData to define a string array of keys to use as table columns.
constructor
constructor(config?: SfdxResult);
property data
data: AnyJson;
property tableColumnData
tableColumnData?: any;
property ux
ux: UX;
method display
display: () => void;
class SfdxCommand
abstract class SfdxCommand extends Command {}
See Also
https://github.com/oclif/command
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.
@oclif/command
property args
protected args: OutputArgs;
property configAggregator
protected configAggregator: SfdxConfigAggregator;
property deprecated
protected static deprecated?: Deprecation;
property flags
static readonly flags: Interfaces.FlagInput<T>;
property flags
protected flags: OutputFlags<any>;
property flagsConfig
protected static flagsConfig: FlagsConfig;
property hubOrg
protected hubOrg?: Org;
property lifecycleEventNames
protected readonly lifecycleEventNames: string[];
event names to be registered for command specific hooks
property logger
protected logger: Logger;
property org
protected org?: Org;
property project
protected project?: SfProject;
property requiresDevhubUsername
protected static requiresDevhubUsername: boolean;
property requiresProject
protected static requiresProject: boolean;
property requiresUsername
protected static requiresUsername: boolean;
property result
protected static result: SfdxResult;
property result
protected result: Result;
property statics
readonly statics: typeof SfdxCommand;
property supportsDevhubUsername
protected static supportsDevhubUsername: boolean;
property supportsUsername
protected static supportsUsername: boolean;
property tableColumnData
protected static tableColumnData: string[];
property usage
static readonly usage: string;
property ux
protected ux: UX;
property varargs
protected static varargs: VarargsConfig;
property varargs
protected varargs?: JsonMap;
method assignHubOrg
protected assignHubOrg: () => Promise<void>;
method assignOrg
protected assignOrg: () => Promise<void>;
method assignProject
protected assignProject: () => Promise<void>;
method catch
protected catch: (err: any) => Promise<void>;
method finally
protected finally: (err: Optional<Error>) => Promise<void>;
method formatError
protected formatError: (error: SfError) => string[];
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.
method getJsonResultObject
protected getJsonResultObject: ( result?: AnyJson, status?: number) => { status: number; result: AnyJson };
method getVarArgsConfig
static getVarArgsConfig: () => Partial<VarargsConfig> | undefined;
method init
protected init: () => Promise<void>;
method initLoggerAndUx
protected initLoggerAndUx: () => Promise<void>;
Initialize logger and ux for the command
method parseVarargs
protected parseVarargs: (args?: string[]) => JsonMap;
method run
abstract run: () => Promise<any>;
Actual command run code goes here.
Returns
{Promise} 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.
method shouldEmitHelp
protected shouldEmitHelp: () => boolean;
method warnIfDeprecated
protected warnIfDeprecated: () => void;
class UX
class UX {}
Deprecated
Use Ux from
@salesforce/sf-plugins-core
instead Utilities for interacting with terminal I/O.
constructor
constructor(logger: Logger, isOutputEnabled?: boolean, ux?: any);
Do not directly construct instances of this class -- use UX.create instead.
property cli
cli: any;
property warnings
static warnings: Set<string>;
Collection of warnings that can be accessed and manipulated later.
{Set}
method confirm
confirm: (message: string) => Promise<boolean>;
Prompt the user for confirmation.
Parameter message
The message displayed to the user.
Returns
{Promise} Returns
true
if the user inputs 'y' or 'yes', andfalse
if the user inputs 'n' or 'no'.
method create
static create: () => Promise<UX>;
Create a
UX
instance.Returns
{Promise} A
Promise
of the createdUX
instance.
method error
error: (...args: unknown[]) => UX;
Logs an error at
ERROR
level and conditionally writes tostderr
if stream output is enabled.Parameter args
The errors to log.
Returns
{UX}
method errorJson
errorJson: (obj: object) => UX;
Logs an object as JSON at
ERROR
level and tostderr
.Parameter obj
The error object to log -- must be serializable as JSON.
Returns
{UX}
Throws
{TypeError} If the object is not JSON-serializable.
method formatDeprecationWarning
static formatDeprecationWarning: (def: DeprecationDefinition) => string;
Formats a deprecation warning for display to
stderr
,stdout
, and/or logs.Parameter def
The definition for the deprecated object.
Returns
{string} The formatted deprecation message.
method getSpinnerStatus
getSpinnerStatus: () => Optional<string>;
Get the spinner status.
Returns
{Optional}
method log
log: (...args: string[]) => UX;
Logs at
INFO
level and conditionally writes tostdout
if stream output is enabled.Parameter args
The messages or objects to log.
Returns
{UX}
method logJson
logJson: (obj: Record<string, unknown>) => UX;
Log JSON to stdout and to the log file with log level info.
Parameter obj
The object to log -- must be serializable as JSON.
Returns
{UX}
Throws
{TypeError} If the object is not JSON-serializable.
method pauseSpinner
pauseSpinner: <T>(fn: () => T, icon?: string) => Optional<T>;
Pause the spinner and call the given function.
Parameter fn
The function to be called in the pause.
Parameter icon
The string displayed to the user.
Returns
{T} The result returned by the passed in function.
method prompt
prompt: (name: string, options?: IPromptOptions) => Promise<string>;
Prompt the user for input.
Parameter name
The string that the user sees when prompted for information.
Parameter options
A prompt option configuration.
Returns
{Promise} The user input to the prompt.
method setSpinnerStatus
setSpinnerStatus: (status?: string) => void;
Update the spinner status.
Parameter status
The message displayed to the user.
method startSpinner
startSpinner: ( message: string, status?: string, opts?: OclifActionOptions) => void;
Start a spinner action after displaying the given message.
Parameter message
The message displayed to the user.
Parameter status
The status displayed to the user.
Parameter opts
The options to select whereas spinner will output to stderr or stdout.
method stopSpinner
stopSpinner: (message?: string) => void;
Stop the spinner action.
Parameter message
The message displayed to the user.
method styledHeader
styledHeader: (header: string) => UX;
Logs at
INFO
level and conditionally writes tostdout
in a styled header format if stream output is enabled.Parameter header
The header to be styled.
Returns
{UX}
method styledJSON
styledJSON: (obj: object) => UX;
Log at
INFO
level and conditionally write tostdout
in styled JSON format if stream output is enabled.Parameter obj
The object to be styled for stdout.
Returns
{UX}
method styledObject
styledObject: (obj: object, keys?: string[]) => UX;
Logs at
INFO
level and conditionally writes tostdout
in a styled object format if stream output is enabled.Parameter obj
The object to be styled for stdout.
Parameter keys
The object keys to be written to stdout.
Returns
{UX}
method table
table: ( rows: any[], columns?: TableColumns, options?: CliUx.Table.table.Options) => UX;
Logs at
INFO
level and conditionally writes tostdout
in a table format if stream output is enabled.Parameter rows
The rows of data to be output in table format.
Parameter columns
Table column options
Parameter options
The SfdxTableOptions to use for formatting.
Returns
{UX}
method warn
warn: (message: string) => UX;
Logs a warning as
WARN
level and conditionally writes tostderr
if the log level isWARN
or above and stream output is enabled. The message is added to the static UX.warnings set if stream output is _not_ enabled, for later consumption and manipulation.Parameter message
The warning message to output.
Returns
{UX}
See Also
UX.warnings
Interfaces
interface SfdxResult
interface SfdxResult {}
property data
data?: AnyJson;
property display
display?: (this: Result) => void;
property tableColumnData
tableColumnData?: TableColumns;
Type Aliases
type FlagsConfig
type FlagsConfig = { [key: string]: Optional<flags.Boolean | flags.Option | flags.Builtin>; /** * Adds the `apiversion` built-in flag to allow for overriding the API * version when executing the command. */ apiversion?: flags.Builtin; /** * Adds the `concise` built-in flag to allow a command to support concise output, * which is useful when the output can be overly verbose, such as test results. * Note that this must be implemented by the command. */ concise?: flags.Builtin; /** * Adds the `quiet` built-in flag to allow a command to completely suppress output. * Note that this must be implemented by the command. */ quiet?: flags.Builtin; /** * Adds the `verbose` built-in flag to allow a command to support verbose output, * which is useful to display additional command results. * Note that this must be implemented by the command. */ verbose?: flags.Builtin; targetdevhubusername?: never; targetusername?: never;};
The configuration of flags for an SfdxCommand class, except for the following:
*
json
andloglevel
are configured automatically for all SfdxCommand classes. *targetusername
is enabled using eitherSfdxCommand.supportsUsername
orSfdxCommand.requiresUsername
. *targetdevhubusername
is enabled using eitherSfdxCommand.supportsDevhubUsername
orSfdxCommand.requiresDevhubUsername
.Additionally,
apiversion
is enabled automatically if any of the static*Username
booleans are set, but may be configured here explicitly as well if those settings are not required.public static flagsConfig: FlagsConfig = {name: flags.string({ char: 'n', required: true, description: 'name of the resource to create' }),wait: flags.minutes({ description: 'number of minutes to wait for creation' }),notify: flags.url({ description: 'url to notify upon completion' })};
type TableColumns
type TableColumns = CliUx.Table.table.Columns<any> | string[];
A table option configuration type. May be a detailed configuration, or more simply just a string array in the simple cases where table header values are the only desired config option.
Namespaces
namespace flags
namespace flags {}
Deprecated
Use Flags from
@salesforce/sf-plugins-core
instead
type Any
type Any<T> = Omit<Partial<Interfaces.Flag<T>>, 'deprecated'> & SfdxProperties;
type Array
type Array<T = string> = Option<T[]> & { delimiter?: string;};
type BaseBoolean
type BaseBoolean<T> = Partial<Interfaces.BooleanFlag<T>>;
type Boolean
type Boolean<T = any> = BaseBoolean<T> & SfdxProperties;
type Bounds
type Bounds<T> = { min?: T; max?: T;};
type Builtin
type Builtin = { type: 'builtin';} & Partial<SfdxProperties>;
type DateTime
type DateTime = Option<Date>;
type Deprecatable
type Deprecatable = { deprecated?: Deprecation;};
type Describable
type Describable = { description: string; longDescription?: string;};
type Discriminant
type Discriminant = { kind: Kind;};
type Discriminated
type Discriminated<T> = T & Discriminant;
type Enum
type Enum<T> = Interfaces.EnumFlagOptions<T> & SfdxProperties;
type Input
type Input<T extends Interfaces.FlagOutput> = Interfaces.FlagInput<T>;
type Kind
type Kind = keyof typeof flags;
type MappedArray
type MappedArray<T> = Omit<flags.Array<T>, 'options'> & { map: (val: string) => T; options?: T[];};
type Milliseconds
type Milliseconds = Option<Duration> & Bounds<Duration | number>;
type Minutes
type Minutes = Option<Duration> & Bounds<Duration | number>;
type Number
type Number = Option<number> & NumericBounds;
type NumericBounds
type NumericBounds = Bounds<number>;
type Option
type Option<T = any> = Omit<Partial<CustomOptionFlag<T>>, 'deprecated'> & SfdxProperties & Validatable;
type Output
type Output = Interfaces.FlagOutput;
type Seconds
type Seconds = Option<Duration> & Bounds<Duration | number>;
type SfdxProperties
type SfdxProperties = Describable & Deprecatable;
type String
type String = Option<string>;
type Url
type Url = Option<URL>;
type Validatable
type Validatable = { validate?: string | RegExp | ((val: string) => boolean);};
Package Files (4)
Dependencies (6)
Dev Dependencies (24)
- @salesforce/dev-config
- @salesforce/dev-scripts
- @salesforce/prettier-config
- @salesforce/ts-sinon
- @typescript-eslint/eslint-plugin
- @typescript-eslint/parser
- chai
- eslint
- eslint-config-prettier
- eslint-config-salesforce
- eslint-config-salesforce-license
- eslint-config-salesforce-typescript
- eslint-plugin-header
- eslint-plugin-import
- eslint-plugin-jsdoc
- husky
- mocha
- nyc
- prettier
- pretty-quick
- sinon
- ts-node
- typescript
- wireit
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@salesforce/command
.
- Markdown[](https://www.jsdocs.io/package/@salesforce/command)
- HTML<a href="https://www.jsdocs.io/package/@salesforce/command"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 5183 ms. - Missing or incorrect documentation? Open an issue for this package.