Create an instance of the service provider with the specified details.
the priority of the service.
optionally support checking env variables for default argument values.
optionally enable configuration file support for default argument values.
optionally enable OS-native secret storage via Bun.secrets for resolving
secrets embedded in default argument values: configEnabled must be true in this case
optionally set the syntax of the configuration file, defaults to JSON.
OptionalcommandRegistry: CommandRegistry
optionally provide the registry of all commands, required for the config:get,
config:set and config:unset commands to be provided.
OptionalsecretsApi: SecretsApi
optionally override the OS secret store used for storing SECRET default values.
ReadonlyconfigReadonlyconfigReadonlyenvReadonlysecretReadonlyserviceThe ID which identifies the service provided.
ReadonlyserviceUsed to determine the order in which multiple service instances will be initialised. Higher values will be initialised before lower values.
The DefaultConfigurationService which owns the configuration data, for trusted wiring and tests.
Write the configuration file, if isDirty is true - for KeyValueServiceProvider's
exclusive use, via its direct reference to this provider, called from its shutdown-time
flush task.
whether any scoped KeyValueService has unwritten changes.
Retrieve the default command argument values (if any) for the provided Command.
This will retrieve values both from the configuration location and environment variables.
the CLIConfig to use for retrieving configuration keys.
the Command instance to retrieve default argument values for.
OptionalgroupCommand: GroupCommand
the GroupCommand if the command is a group member. The configuration file key
is then <group name>:<command name> and the env var names include the group name.
Get-or-create the underlying, raw ValueNode Map for the given scope - for
KeyValueServiceProvider's exclusive use, via its direct reference to this provider.
whether scopeKey is a command name or a service/task ID.
the command name or service/task ID to scope the key-value data to.
Return ServiceInfo containing the service and any commands it provides which should be registered in the CLI.
Initialise the service. This will be invoked AFTER any GlobalModifierCommand provided in the ServiceInfo have been invoked (if specified as CLI arguments or CLI configuration).
NOTE: Other services within the provided context will only have been initialised if they have a higher servicePriority value than the current service.
Provides configuration of default command arguments using a configuration file and/or environment variables.
The same configuration file also backs the raw, per-scope key-value data consumed by KeyValueServiceProvider (which holds a direct reference to this provider - see getKeyValueData and flushIfDirty). The configuration data and its persistence are owned by DefaultConfigurationService, which is passed directly to the
configgroup commands. Only a view exposing the config file location is registered under CONFIGURATION_SERVICE_ID.Default Command Arguments
Configuration of default Values for Command instances is supported if they have defined Command.enableConfiguration as
true.Two sources of configuration are supported and both are expected to be manually managed by the user of the CLI.
Configuration File
A file (JSON by default, see ConfigFormat) where the structure matches Values and the defaults are stored under a top level
defaultsproperty. The second level of properties is used to refer to Command.name (or<group name>:<member name>for a member of a GroupCommand) and the contained values are treated as command Values. As an example:The syntax of the file is set by the
configFormatconstructor argument: JSON (the default), or YAML or TOML from theyamlandtomlentry points of this package. The format is never inferred from the file name or extension and existing files are not migrated between formats. For YAML and TOML, comments and layout in the existing file are preserved when it is written back.The default location of the configuration file is
$HOME/.<application_name>.<format extension>. If$HOMEis not defined no default configuration will be used. The location of the configuration file can be modified via the ConfigCommand.NOTE: Secrets in default arguments are referenced in the config file or an environment variable using the sentinel format
__SECRET__:<bun_secret_name>and resolved from the OS secret store before being returned as default argument values. A command's defaults may only reference secrets stored for that command viaconfig set(nameddefaults_Z<command>_Z<option path>, each part escaped). See KeyValueServiceProvider for the generic key-value store which uses the same secret sentinel mechanism.Environment Variables
Values are parsed using a key path defined by custom Argument.configurationKey values or using the default naming scheme defined within Argument.configurationKey.
NOTE: Any values set by environment variables will override those sourced from the configuration file.
The argument key path is derived for an argument (or nested argument) as follows:
Argument configuration keys are concatenated with a
_separator. Any arguments which support array values must by suffixed with_and an explicit array index. If the root argument in the path does not use a custom Argument.configurationKey then the key path is additionally prefixed with the CLIConfig.name, the GroupCommand.name (if the command is a group member) and the Command.name with_separators. This is best explained with examples...No custom configuration key examples:
MyCLI, command:globalCommand1, global command argument => environment variable:MYCLI_GLOBALCOMMAND1MyCLI, command:command1, simple root argument:arg1=> environment variable:MYCLI_COMMAND1_ARG1MyCLI, group:group1, member command:member1, simple root argument:arg1=> environment variable:MYCLI_GROUP1_MEMBER1_ARG1MyCLI, command:command1, array root argument, 1st element:arg2[0]=> environment variable:MYCLI_COMMAND1_ARG2_0MyCLI, command:command1, argument is a digit so it is by default suffixed with_:3=> environment variable:MYCLI_COMMAND1__3MyCLI, command:command1, nested sub-argument:arg1.arg2=> environment variable:MYCLI_COMMAND1_ARG1_ARG2MyCLI, command:command1, nested sub-argument with both levels being arrays and referring to the 2nd element of each:arg1[1].arg2[1]=> environment variable:MYCLI_COMMAND1_ARG1_1_ARG2_2Custom configuration key at the root level (and therefore not prefixed with CLI and command names) examples:
MyCLI, command:globalCommand1, global command argument, global command argument configuration key:FOO=> environment variable:FOO`MyCLI, command:command1, simple root argument:arg1, arg1 configuration key:FOO=> environment variable:FOOMyCLI, command:command1, array root argument, 1st element:arg2[0], arg1 configuration key:BAR=> environment variable:BAR_0Custom configuration key not at the root level (and therefore prefixed with CLI and command names) examples:
MyCLI, command:command1, nested sub-argument:arg1.arg2, arg2 configuration key:FOO=> environment variable:MYCLI_COMMAND1_ARG1_FOOMyCLI, command:command1, nested sub-argument with both levels being arrays and referring to the 2nd element of each:arg1[1].arg2[1], arg2 configuration key:BAR=> environment variable:MYCLI_COMMAND1_ARG1_1_BAR_2NOTE: Any default values from the above configuration sources will be overridden by any arguments provided on the command line.