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 provide a KeyValueService implementation: configEnabled must be true in this case
optionally enable OS-native secret storage via Bun.secrets: configEnabled must be true in this case
ReadonlyconfigReadonlyenvReadonlykeyReadonlysecretReadonlyserviceThe 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.
Indicate that the contained DefaultKeyValueService should have any current scope cleared.
If a scope is currently set and changes have been made to the key-value data, they will be written to the current configuration location.
Retrieve the default command argument values (if any) for the provided Command.
This will retrieve values both from the configuration location and environment variables.
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.
Indicate that the contained DefaultKeyValueService should be set to have a scope of the provided command name.
the name of the command to scope the key-value data to.
Indicate that the contained DefaultKeyValueService should be set to have a scope of the provided service ID.
the ID of the service to scope the key-value data to.
Provides:
Default Command Arguments
Configuration of default ArgumentValues 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 JSON file where the structure matches ArgumentValues and the defaults are stored under a top level
defaultsproperty. The second level of properties is used to refer to Command.name and the contained values are treated as command ArgumentValues. As an example:The default location of the configuration file is
$HOME/.<application_name>.json. If$HOMEis not defined no default configuration will be used. The location of the configuration file can be modified via the ConfigCommand.NOTE: You may store default arguments for secrets by manually configuring secrets in your OS credential store and referencing them in the config file using the sentinel format
__SECRET__:<bun_secret_name>. These values will be resolved from the OS secret store before being returned as default argument values. See "Generic Key-Value Service" below.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 suffixed with the CLIConfig.name 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, 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.
Generic Key-Value Service
The same configuration file above is used to provide storage for the provided KeyValueService. The values are stored under a top level
key-valuesproperty. These are expected to not be modified by the user of the CLI.The second and third level of properties is used to scope the key-values to specific command names (via Command.name values) and specific service IDs (via ServiceProvider.serviceId values). Both keys and values are string based.
Values may be stored as OS-native secrets via KeyValueService.setKey with
isSecret=true. When a value is stored as a secret, a sentinel value of the format__SECRET__:<bun_secret_name>is stored in the config file instead of the actual value. The actual value is stored in the OS credential store via Bun.secrets. The sentinel prefix__SECRET__:is reserved and must not be used for regular key-value data.Secret support requires
secretServiceEnabled=truein the constructor (which also requiresconfigEnabled=true).As an example: