A git-config style configuration management library and CLI tool.
- Multiple configuration layers with priority: args > env > local > global > default
- TOML-based configuration files
- Environment variable support
- Sectioned configuration keys (e.g.,
section.key,section.subsection.key) - JSON and JSONL output formats for CLI
cargo install --path .# Get a configuration value
emx-config get user.name
# Set a configuration value (local)
emx-config set user.name "John Doe"
# Set a configuration value (global)
emx-config set --global user.name "John Doe"
# List all configuration values
emx-config list
# List with source layer
emx-config list --show-source
# Unset a configuration value
emx-config unset user.name
# Output in JSON format (nested JSON object)
emx-config --json get user.name
emx-config --json list
# Output in JSONL format (one JSON object per line, machine-readable)
emx-config --jsonl get user.name
emx-config --jsonl listuse emx_config_core::{Config, ConfigLayer};
use std::collections::HashMap;
// Create a config with defaults
let mut defaults = HashMap::new();
defaults.insert("timeout".to_string(), toml::Value::Integer(30));
let config = Config::builder()
.with_defaults(defaults)
.build()
.unwrap();
// Get a value
let timeout = config.get_int("timeout").unwrap();Configuration values are loaded from multiple sources in order of priority (highest first):
- Arguments - Command-line arguments
- Environment - Environment variables and
.envfile - Local -
./config.toml(orEMX_CONFIG_NAMEvalue) - Global -
$EMX_HOME/config.toml(orEMX_CONFIG_NAMEvalue) - Default - Default values provided when building the config
EMX_HOME- Directory for global configurationEMX_CONFIG_NAME- Name of the configuration file (default:config.toml)EMX_LOAD_ENV- Whether to load environment variables (default:1)- When set to
0, environment variables and.envfile are not loaded EMX_CONFIG_NAMEandEMX_HOMEare still respected
- When set to
Configuration keys can be specified in two formats:
-
Underscore notation (recommended for simple keys):
timeout- Top-level keyuser_name- Simple keytest_value- Simple key
-
Dot notation (for nested sections):
user.name- Key inusersectiongit.branch.main- Key in nested sections
Both notations work and can be used interchangeably.
Configuration keys use underscores to represent nesting in environment variables:
timeout→EMX_TIMEOUTuser_name→EMX_USER_NAMEtest.value→EMX_TEST_VALUE(bothtest.valueandtest_valuemap toEMX_TEST_VALUE)git.branch.main→EMX_GIT_BRANCH_MAIN
Note: Environment variables use underscores (_) while configuration files may use dots (.) or TOML tables for nesting. Both styles are supported and will correctly map to the same environment variable.
MIT