Using existing command line args with quicli


#1

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

?


#2

I would probably use the flatten feature here. https://docs.rs/structopt/0.2.14/structopt/#flattening

(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,
}