Skip to main content

Crate lino_arguments

Crate lino_arguments 

Source
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):

  1. CLI arguments (manually entered options)
  2. Environment variables (from process env)
  3. .lenv file (local environment overrides)
  4. .env file (standard dotenv, for compatibility)
  5. 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: true

Macros§

arg
Create an Arg from a usage string.
command
Requires cargo feature flag to be enabled.

Structs§

Config
Resolved configuration values from the functional API.
ConfigBuilder
Builder for functional-style configuration.
LinoEnv
LinoEnv - A struct to read and write .lenv files.

Enums§

ConfigError
Errors that can occur during configuration

Traits§

Args
Parse a set of arguments into a user-defined container.
LinoParser
Extension trait for clap::Parser that provides methods for parsing with custom .lenv/.env file paths.
Parser
Parse command-line arguments into Self.
Subcommand
Parse a sub-command into a user-defined enum.
ValueEnum
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 .lenv and .env files into the process environment.
init_with
Load specified .lenv and .env files into the process environment.
load_env_file
Load environment variables from a .env file (standard KEY=VALUE format).
load_env_file_override
Load environment variables from a .env file, overwriting existing values.
load_lenv_file
Load environment variables from a .lenv file.
load_lenv_file_override
Load environment variables from a .lenv file, 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 Args impl.
Parser
Generates the Parser implementation.
Subcommand
Generates the Subcommand impl.
ValueEnum
Generates the ValueEnum impl.