lino-arguments (Rust)
A unified configuration library combining environment variables and CLI arguments with a clear priority chain. Works like a combination of clap and dotenvy, but uses .lenv files via lino-env.
Overview
lino-arguments provides a unified configuration system that automatically loads configuration from multiple sources with a clear priority chain:
- CLI arguments - Highest priority (manually entered options)
- Environment variables - Already set in the process
.lenvfile - Links Notation environment file.envfile - Standard dotenv file (for compatibility)- Default values - Fallback values
Installation
Add to your Cargo.toml:
[]
= "0.2"
Struct-Based Usage (drop-in clap replacement)
Replace use clap::Parser with use lino_arguments::Parser, add lino_arguments::init() before Args::parse() — everything else stays the same:
use Parser;
With a .lenv file:
PORT: 8080
API_KEY: my-secret-key
Or a .env file:
PORT=8080
API_KEY=my-secret-key
The priority chain ensures CLI arguments always win:
# Uses default (3000)
# Uses .lenv value (8080)
# (if PORT: 8080 is in .lenv)
# Uses env var (9090)
PORT=9090
# Uses CLI argument (7070)
init() Functions
| Function | Description |
|---|---|
init() |
Load .lenv + .env files into process env |
init_with(lenv, env) |
Load specified files into process env |
LinoParser Trait (alternative one-liner API)
For a single-call approach, use the LinoParser trait:
use ;
| Method | Description |
|---|---|
lino_parse() |
Load .lenv + .env, then parse CLI args |
lino_parse_with(lenv, env) |
Load specified files, then parse |
lino_parse_from(args) |
Load .lenv + .env, parse custom args (for testing) |
lino_parse_from_with(args, lenv, env) |
Load specified files, parse custom args |
Functional Usage (like JavaScript's makeConfig)
For quick scripts or when you prefer not to define structs, use the functional builder API:
use make_config_from;
API Reference
Re-exported Clap Types
Parser- Derive macro and trait for struct-based CLI parsingArgs- Derive macro for argument groupsSubcommand- Derive macro for subcommandsValueEnum- Derive macro for enum value argumentsarg!- Macro for inline argument definitionscommand!- Macro for command metadata
Initialization Functions
| Function | Description |
|---|---|
init() |
Load .lenv + .env files from current directory |
init_with(lenv_path, env_path) |
Load specified .lenv and .env files |
File Loading Functions
| Function | Description |
|---|---|
load_lenv_file(path) |
Load .lenv file (won't overwrite existing env vars) |
load_lenv_file_override(path) |
Load .lenv file (overwrites existing env vars) |
load_env_file(path) |
Load .env file (won't overwrite existing env vars) |
load_env_file_override(path) |
Load .env file (overwrites existing env vars) |
Functional Configuration
make_config(configure)
Create configuration from CLI arguments and environment:
use make_config;
let config = make_config;
make_config_from(args, configure)
Same as make_config but accepts custom arguments (useful for testing):
use make_config_from;
let config = make_config_from;
assert_eq!;
ConfigBuilder Methods
| Method | Description |
|---|---|
.name(name) |
Set application name |
.about(description) |
Set application description |
.version(version) |
Set application version |
.lenv(path) |
Load .lenv file (without overriding existing env vars) |
.lenv_override(path) |
Load .lenv file (overriding existing env vars) |
.env(path) |
Load .env file (without overriding existing env vars) |
.env_override(path) |
Load .env file (overriding existing env vars) |
.option(name, desc, default) |
Define a string option |
.option_short(name, short, desc, default) |
Define a string option with short flag |
.flag(name, desc) |
Define a boolean flag |
.flag_short(name, short, desc) |
Define a boolean flag with short flag |
Config Methods
| Method | Description |
|---|---|
.get(key) |
Get value as string |
.get_int(key, default) |
Get value as integer |
.get_bool(key) |
Get value as boolean |
.has(key) |
Check if key exists |
Environment Variable Helpers
getenv(key, default)
Get environment variable as string with case-insensitive lookup.
let api_key = getenv; // Tries API_KEY, apiKey, etc.
getenv_int(key, default)
Get environment variable as integer.
let port = getenv_int;
getenv_bool(key, default)
Get environment variable as boolean. Accepts: "true", "false", "1", "0", "yes", "no".
let debug = getenv_bool;
Case Conversion Utilities
to_upper_case(s)- Convert to UPPER_CASEto_camel_case(s)- Convert to camelCaseto_kebab_case(s)- Convert to kebab-caseto_snake_case(s)- Convert to snake_caseto_pascal_case(s)- Convert to PascalCase
use ;
assert_eq!;
assert_eq!;
assert_eq!;
Examples
# Run struct-based example
# Run functional example
# Use environment variables
PORT=8080
Testing
# Run all tests
# Run tests with output
# Run specific test
Development
# Build
# Build release
# Run clippy
# Format code
License
This is free and unencumbered software released into the public domain. See the LICENSE file for details.