Options
All
  • Public
  • Public/Protected
  • All
Menu

Aliases specify alternate names for groups of properties used by the Salesforce CLI, such as orgs. By default, all aliases are stored under 'orgs', but groups allow aliases to be applied for other commands, settings, and parameters.

Note: All aliases are stored at the global level.

extends

ConfigGroup

example

const aliases = await Aliases.retrieve(); aliases.set('myAlias', 'username@company.org'); await aliases.write(); // Shorthand to get an alias. const username: string = await Aliases.fetch('myAlias');

see

https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_cli_usernames_orgs.htm

Hierarchy

Implements

Index

Constructors

constructor

Properties

Protected options

options: Options

Methods

access

  • access(perm: number): Promise<boolean>
  • Determines if the config file is read/write accessible.

    see

    fs.access

    Parameters

    • perm: number

      The permission.

    Returns Promise<boolean>

    true if the user has capabilities specified by perm.

awaitEach

  • awaitEach(actionFn: function): Promise<void>
  • Asynchronously invokes actionFn once for each key-value pair present in the config object.

    Parameters

    • actionFn: function

      The function (key: string, value: ConfigValue) => Promise<void> to be called for each element.

        • Parameters

          Returns Promise<void>

    Returns Promise<void>

clear

  • clear(): void

entries

exists

  • exists(): Promise<boolean>
  • Check to see if the config file exists.

    Returns Promise<boolean>

    True if the config file exists and has access, false otherwise.

forEach

  • forEach(actionFn: function): void
  • Invokes actionFn once for each key-value pair present in the config object.

    Parameters

    • actionFn: function

      The function (key: string, value: ConfigValue) => void to be called for each element.

    Returns void

get

getContents

getGroup

  • Get all config content for a group.

    Parameters

    • Default value group: string = this.defaultGroup

    Returns Optional<ConfigContents>

    The contents.

getInGroup

  • getInGroup(key: string, group?: undefined | string): Optional<ConfigValue>
  • Returns the value associated to the key and group, or undefined if there is none.

    Parameters

    • key: string

      The key.

    • Optional group: undefined | string

    Returns Optional<ConfigValue>

getKeysByValue

getPath

  • getPath(): string
  • Returns the path to the config file.

    Returns string

has

  • has(key: string): boolean
  • Returns a boolean if an element with the specified key exists in the default group.

    override

    Parameters

    • key: string

      The key.

    Returns boolean

init

  • init(): Promise<void>

isGlobal

  • isGlobal(): boolean
  • Returns true if this config is using the global path, false otherwise.

    Returns boolean

keys

  • keys(): string[]

read

  • Read the config file and set the config contents.

    throws

    {SfdxError} {name: 'UnexpectedJsonFileFormat'}: There was a problem reading or parsing the file.

    Parameters

    • Default value throwOnNotFound: boolean = false

    Returns Promise<ConfigContents>

    The config contents of the config file.

set

setContents

setContentsFromObject

  • setContentsFromObject<U>(obj: U): void

setDefaultGroup

  • setDefaultGroup(group: string): void
  • Sets the default group for all BaseConfigStore methods to use.

    throws

    {SfdxError} {name: 'MissingGroupName'}: The group parameter is null or undefined.

    Parameters

    • group: string

      The group.

    Returns void

setInGroup

  • Sets the value for the key and group in the config object.

    Parameters

    • key: string

      The key.

    • Optional value: ConfigValue
    • Optional group: undefined | string

    Returns ConfigContents

    The contents.

stat

  • stat(): Promise<fsStats>
  • Get the stats of the file.

    see

    fs.stat

    Returns Promise<fsStats>

    The stats of the file.

toObject

  • toObject(): JsonMap

unlink

  • unlink(): Promise<void>
  • Delete the config file if it exists.

    see

    fs.unlink

    Returns Promise<void>

    True if the file was deleted, false otherwise.

unset

  • unset(key: string): boolean
  • Removes an element with the specified key from the default group.

    override

    Parameters

    • key: string

      The key.

    Returns boolean

    True if the item was deleted.

unsetAll

  • unsetAll(keys: string[]): boolean
  • Returns true if all elements in the config object existed and have been removed, or false if all the elements do not exist (some may have been removed). {@link BaseConfigStore.has(key)} will return false afterwards.

    Parameters

    • keys: string[]

      The keys.

    Returns boolean

updateValue

  • updateValue(key: string, value: ConfigValue, group?: undefined | string): Promise<void>
  • Set a value on a group.

    Parameters

    • key: string

      The key.

    • value: ConfigValue

      The value.

    • Optional group: undefined | string

    Returns Promise<void>

    The promise resolved when the value is set.

updateValues

  • updateValues(newEntries: object, group?: undefined | string): Promise<any>
  • Set a group of entries in a bulk save.

    Parameters

    • newEntries: object

      An object representing the aliases to set.

    • Optional group: undefined | string

    Returns Promise<any>

    The new property that was saved.

values

write

  • Write the config file with new contents. If no new contents are passed in it will write the existing config contents that were set from ConfigFile.read, or an empty file if ConfigFile.read was not called.

    Parameters

    Returns Promise<any>

    The written contents.

Static create

  • create<P, T>(this: object, options: P): Promise<T>
  • Asynchronously constructs and initializes a new instance of a concrete subclass with the provided options.

    Type parameters

    • P

    • T: AsyncCreatable<P>

    Parameters

    • this: object
    • options: P

      An options object providing initialization params to the async constructor.

    Returns Promise<T>

Static fetch

  • fetch(key: string, group?: ORGS): Promise<string>
  • Get an alias from a key and group. Shorthand for Alias.retrieve().get(key).

    Parameters

    • key: string

      The value of the alias to match

    • Default value group: ORGS = AliasGroup.ORGS

    Returns Promise<string>

    The promise resolved when the alias is retrieved

Static getDefaultOptions

Static getFileName

  • getFileName(): string
  • The aliases state file filename.

    override

    Returns string

Static getOptions

  • getOptions(defaultGroup: string, filename?: undefined | string): Options
  • Get ConfigGroup specific options, such as the default group.

    Parameters

    • defaultGroup: string

      The default group to use when creating the config.

    • Optional filename: undefined | string

    Returns Options

Static parseAndUpdate

  • parseAndUpdate(aliasKeyAndValues: string[], group?: AliasGroup): Promise<any>
  • Updates a group of aliases in a bulk save.

    example

    const aliases = await Aliases.parseAndUpdate(['foo=bar', 'bar=baz'])

    Parameters

    • aliasKeyAndValues: string[]

      An array of strings in the format <alias>=<value>. Each element will be saved in the Aliases state file under the group.

    • Default value group: AliasGroup = AliasGroup.ORGS

    Returns Promise<any>

    The new aliases that were saved.

Static resolveRootFolder

  • resolveRootFolder(isGlobal: boolean): Promise<string>
  • Helper used to determined what the local and global folder point to.

    Parameters

    • isGlobal: boolean

      True if the config should be global. False for local.

    Returns Promise<string>

    The file path of the root folder.

Static retrieve

  • retrieve<T>(options?: Options): Promise<T>