autorun_config 0.1.0

Macros to easily create configurations that can pull their data from command line arguments or environment variables
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 2 items with examples
  • Size
  • Source code size: 20.51 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 36.05 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • chazfg
autorun_config-0.1.0 has been yanked.

Placeholder readme

usage:

use clap::{arg, command, value_parser};
use autorun_config::FromEnv;

#[derive(FromEnv, Debug)]
struct RuntimeConfig {
  uri: String,
  #[env(default = 22)]
  port: i32,
}


fn bootstrap() -> RuntimeConfig {
  let run_args = command!()
    .arg(
      .arg!(--uri <URI>).required(false)
    )
    .arg(
      .arg!(--port <PORT>).required(false).value_parser(value_parser!(i32))
    )
    .get_matches();

  RuntimeConfig::init_from_env(run_args)
}

When you define the bootstrap function and pass in the run args, the macro will derive the look ups to find the variables declared in the struct. Note that the field in the struct are equal to the "--" arguments. The macro will take it's field name and check for <field_name> in the clap arg parser and check for <FIELD_NAME> in the environment. Right now I only handle strings and i32. There is a default field you can specify as well.

Preference order: If found in command line: Return var else: if found in environment: Return var else: if default specificed: Return default else: panic!()