Using existing command line args with quicli

Hello all. I am using quicli for a command line program.

I have too many binaries in my crate. And there are some common args for every binary. For example, time , timestep , particles , print_frequency . Now, depending on the binary new args will be added. Say If I want to create a binary simulating dam_break , it has spacing , length , height` and etc.

Currently I can do

#[derive(Debug, StructOpt)]
struct Cli {
    #[structopt(long = "time", short = "tf", default_value = "1")]
    tf: f32,
    #[structopt(long = "time_step", short = "dt", default_value = "1")]
    dt: f32
}

is there a way to extend the cli args

?

I would probably use the flatten feature here. structopt - Rust

(untested, but I think this should work)

#[derive(Debug, StructOpt)]
struct GlobalOpt {
    #[structopt(long = "time", short = "tf", default_value = "1")]
    tf: f32,
    #[structopt(long = "time_step", short = "dt", default_value = "1")]
    dt: f32
}

#[derive(Debug, StructOpt)]
struct MyOpt {
    #[structopt(long = "my-opt", short = m", default_value = "1")]
    my_opt: f32,
    #[structopt(flatten)]
    global_opt: GlobalOpt,
}
1 Like