RBCli provides built-in support for creating and managing userspace configuration files. It does this through two chains: the defaults chain and the user chain.
The defaults chain allows you to specify sane defaults for your CLI tool throughout your code. This gives you the ability to declare configuration alongside the code, and allows RBCli to generate a user config automatically given your defaults. There are two ways to set them:
userconf/
directory in your project and they will automatically be loadedconfig/userspace.rb
application/commands/*.rb
DSL statements appear in both of the above locations as the following:
config_default :name, description: '<description_help_text>', default: '<default_value>'
The user chain has two functions: generating and loading configuration from a YAML file on the end user’s machine.
Rbcli will determine the correct location to locate the user configuration based on two factors:
config/userspace.rb
--config-file=<filename>
option (overrides #1)To configure the default location, edit config/userspace.rb
:
config_userfile '~/.mytool', merge_defaults: true, required: false
path/to/config/file
/etc
such as /etc/mytool/userconf.yaml
merge_defaults
true
, default settings override user settings. If set to false
, default settings are not loaded at all and the user is required to have all values specified in their config.required
true
the application will not run if the file does not exist. A message will be displayed to the user to run your application with the --generate-config
option to generate the file given your specified defaults.Users can generate configs by running yourclitool --generate-config
. This will generate a config file at the tool’s default location specified in the DSL. This location can be overridden via the --config-file=<filename>
option.