clementine_core::cli

Function get_config_source

Source
pub fn get_config_source(
    read_from_env_name: &'static str,
    provided_arg: Option<PathBuf>,
) -> Result<ConfigSource, BridgeError>
Expand description

Selects a configuration source for the main config or the protocol paramset.

Configuration can be loaded either from a file specified by a path in the CLI args, or from environment variables.

Selection logic is as follows:

  1. If the named environment variable (eg. READ_CONFIG_FROM_ENV) is not set or if the named environment variable is set to 0 or off, we use the file path provided in the CLI args (fail if not provided)

  2. If the named environment variable is set to 1 or on, we explicitly read from the environment variable

  3. If the named environment variable is set to an unknown value, we print a warning and default to environment variables

ยงExamples

# Load config from a file and protocol params from a file
READ_CONFIG_FROM_ENV=0 READ_PARAMSET_FROM_ENV=0 clementine-core verifier --config /path/to/config.toml --protocol-params /path/to/protocol-params.toml

# or
# define all config variables in the environment
export CONFIG_ONE=1
export PARAM_ONE=1
# and source from environment variables
READ_CONFIG_FROM_ENV=1 READ_PARAMSET_FROM_ENV=1 clementine-core verifier

# or
# source paramset from environment variables but use config from a file
export PARAM_ONE=1
export PARAM_TWO=1
READ_CONFIG_FROM_ENV=0 READ_PARAMSET_FROM_ENV=1 clementine-core verifier --config /path/to/config.toml

# WRONG usage (will use environment variables for both config and paramset)
export CONFIG_ONE=1
export PARAM_ONE=1
READ_CONFIG_FROM_ENV=1 READ_PARAMSET_FROM_ENV=1 clementine-core --config /path/to/config.toml --protocol-params /path/to/protocol-params.toml