Expand description
lino-arguments - A unified configuration library
Combines environment variables and CLI arguments into a single easy-to-use configuration system with clear priority ordering.
Works like a combination of clap and
dotenvy, but also with support for .lenv files
via lino-env.
Priority (highest to lowest):
- CLI arguments (manually entered options)
- Environment variables (from process env)
.lenvfile (local environment overrides).envfile (standard dotenv, for compatibility)- Default values
§Drop-in Replacement for clap
Just replace use clap::Parser with use lino_arguments::Parser —
everything else stays exactly the same. .lenv and .env files are
loaded automatically at startup before main() runs:
ⓘ
// Only change: import from lino_arguments instead of clap
use lino_arguments::Parser;
#[derive(Parser, Debug)]
#[command(name = "my-app")]
struct Args {
#[arg(long, env = "PORT", default_value = "3000")]
port: u16,
#[arg(long, env = "API_KEY")]
api_key: Option<String>,
#[arg(long, env = "VERBOSE")]
verbose: bool,
}
fn main() {
let args = Args::parse(); // .lenv + .env already loaded
println!("port = {}", args.port);
}§Functional Usage (like the JavaScript API)
ⓘ
use lino_arguments::make_config;
let config = make_config(|c| {
c.lenv(".lenv")
.env(".env")
.option("port", "Server port", "3000")
.option("api-key", "API key", "")
.flag("verbose", "Enable verbose logging")
});
let port: u16 = config.get("port").parse().unwrap();
let verbose: bool = config.get_bool("verbose");§.lenv File Format
The .lenv file format uses : (colon-space) as the separator:
PORT: 8080
API_KEY: my-secret-key
DEBUG: trueMacros§
Structs§
- Config
- Resolved configuration values from the functional API.
- Config
Builder - Builder for functional-style configuration.
- LinoEnv
LinoEnv- A struct to read and write.lenvfiles.
Enums§
- Config
Error - Errors that can occur during configuration
Traits§
- Args
- Parse a set of arguments into a user-defined container.
- Lino
Parser - Extension trait for
clap::Parserthat provides methods for parsing with custom.lenv/.envfile paths. - Parser
- Parse command-line arguments into
Self. - Subcommand
- Parse a sub-command into a user-defined enum.
- Value
Enum - Parse arguments into enums.
Functions§
- getenv
- Get environment variable with default value and case conversion. Tries multiple case formats to find the variable.
- getenv_
bool - Get environment variable as boolean with default value. Tries multiple case formats to find the variable. Accepts: “true”, “false”, “1”, “0”, “yes”, “no” (case-insensitive)
- getenv_
int - Get environment variable as integer with default value. Tries multiple case formats to find the variable.
- init
- Load
.lenvand.envfiles into the process environment. - init_
with - Load specified
.lenvand.envfiles into the process environment. - load_
env_ file - Load environment variables from a
.envfile (standardKEY=VALUEformat). - load_
env_ file_ override - Load environment variables from a
.envfile, overwriting existing values. - load_
lenv_ file - Load environment variables from a
.lenvfile. - load_
lenv_ file_ override - Load environment variables from a
.lenvfile, overwriting existing values. - make_
config - Create a unified configuration using a functional builder API.
- make_
config_ from - Create a unified configuration using a functional builder API with custom arguments.
- read_
lino_ env - Convenience function to read a .lenv file.
- to_
camel_ case - Convert string to camelCase (for config object keys)
- to_
kebab_ case - Convert string to kebab-case (for CLI options)
- to_
pascal_ case - Convert string to PascalCase
- to_
snake_ case - Convert string to snake_case
- to_
upper_ case - Convert string to UPPER_CASE (for environment variables)
- write_
lino_ env - Convenience function to create and write a .lenv file.
Derive Macros§
- Args
- Generates the
Argsimpl. - Parser
- Generates the
Parserimplementation. - Subcommand
- Generates the
Subcommandimpl. - Value
Enum - Generates the
ValueEnumimpl.