Skip to main content

Module cli

Module cli 

Source
Expand description

Command-line configuration with YAML-file + argv precedence.

Port provenance: oa/core/cli.h. Rust translates the Cli<TConfig> template class to Cli<C> with caller-provided closures for YAML loading and option application.

§Precedence

struct defaults < YAML file (-c / --config) < explicit argv flags

§Usage

ⓘ
use oa::Cli;

#[derive(Default)]
struct Config { steps: u64, lr: f32, output: String }

struct MyApp { cli: Cli<Config> }

impl MyApp {
    fn new() -> Self {
        let mut cli = Cli::new("myapp", "Train a model");
        {
            let cfg = cli.config_mut();
            let _ = cfg; // borrow for defaults; options registered below
        }
        let app_ptr = /* pointer trick not needed — use a builder pattern: */
            MyApp { cli };
        app_ptr
    }
}

// Simpler usage — register options before calling parse:
let mut config = Config::default();
let mut cli: Cli<Config> = Cli::new("myapp", "Train a model");
cli.add_option("-s,--steps", |c| &mut c.steps, "number of steps");
cli.add_option("-l,--lr",    |c| &mut c.lr,    "learning rate");
let args: Vec<String> = std::env::args().collect();
if !cli.parse_args(&args[1..]) { return Ok(()); }
let cfg = cli.config();

Structs§

Cli
Command-line configuration with YAML + argv precedence.
Cmd
A named subcommand (or the implicit root command).

Traits§

ParseCliValue
Sealed helper for CLI value parsing.