Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ConfigGroup<T>

A config file that stores config values in groups. e.g. to store different config values for different commands, without having manually manipulate the config.

Note: All config methods are overwritten to use the ConfigGroup.setDefaultGroup.

class MyPluginConfig extends ConfigGroup<ConfigGroup.Options> {
  public static getFileName(): string {
    return 'myPluginConfigFilename.json';
  }
}
const myConfig = await MyPluginConfig.create(ConfigGroup.getOptions('all'));
myConfig.setDefaultGroup('myCommand'); // Can be set in your command's init.
myConfig.set('mykey', 'myvalue'); // Sets 'myKey' for the 'myCommand' group.
myConfig.setInGroup('myKey', 'myvalue', 'all'); // Manually set in another group.
await myConfig.write();

Type parameters

Hierarchy

Implements

Index

Properties

Protected defaultGroup

defaultGroup: string = "default"

Protected options

options: T

Methods

access

  • access(perm: number): Promise<boolean>

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 true if the config file exists and has access, false otherwise.

    Returns Promise<boolean>

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

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

      The group. Defaults to the default group.

    Returns Optional<ConfigValue>

getKeysByValue

getPath

  • getPath(): string

has

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

    Parameters

    • key: string

      The key.

    Returns boolean

init

  • init(): Promise<void>

isGlobal

  • isGlobal(): boolean

keys

  • keys(): string[]

read

  • Read the config file and set the config contents. Returns the config contents of the config file. Throws SfdxError{ name: 'UnexpectedJsonFileFormat' } There was a problem reading or parsing the file.

    Parameters

    • Default value throwOnNotFound: boolean = false

    Returns Promise<ConfigContents>

set

setContents

setContentsFromObject

  • setContentsFromObject<U>(obj: U): void
  • Convert an object to a ConfigContents and set it as the config contents.

    Type parameters

    • U: any

    Parameters

    • obj: U

      The object.

    Returns void

setDefaultGroup

  • setDefaultGroup(group: string): void
  • Sets the default group for all {@link 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

      The value.

    • Optional group: undefined | string

      The group. Uses the default group if not specified.

    Returns ConfigContents

Protected setMethod

stat

  • stat(): Promise<fsStats>

toObject

  • toObject(): JsonMap
  • Convert the config object to a json object.

    Returns JsonMap

unlink

  • unlink(): Promise<void>

unset

  • unset(key: string): boolean
  • Removes an element with the specified key from the default group. Returns true if the item was deleted.

    Parameters

    • key: string

      The key.

    Returns boolean

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. Returns the promise resolved when the value is set.

    Parameters

    • key: string

      The key.

    • value: ConfigValue

      The value.

    • Optional group: undefined | string

      The group.

    Returns Promise<void>

updateValues

  • updateValues(newEntries: Dictionary<ConfigValue>, group?: undefined | string): Promise<Dictionary<ConfigValue>>
  • Set a group of entries in a bulk save. Returns The new properties that were saved.

    Parameters

    • newEntries: Dictionary<ConfigValue>

      An object representing the aliases to set.

    • Optional group: undefined | string

      The group the property belongs to.

    Returns Promise<Dictionary<ConfigValue>>

values

write

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 getDefaultOptions

  • getDefaultOptions(isGlobal?: boolean, filename?: undefined | string): Options
  • Returns the default options for the config file.

    Parameters

    • Default value isGlobal: boolean = false

      If the file should be stored globally or locally.

    • Optional filename: undefined | string

      The name of the config file.

    Returns Options

Static getFileName

  • getFileName(): 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

      The filename of the config file. Uses the static getFileName by default.

    Returns Options

Static resolveRootFolder

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

    Parameters

    • isGlobal: boolean

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

    Returns Promise<string>