Rust Noob here :) using rust clap 3.2.23
I have to 2 subcommands:
- generate (This is responsible for generating item based on input parameters & storing in a backend DB)
#[derive(Args, Debug)]
#[clap(group(ArgGroup::new("qwerty").required(true).multiple(true)))]
pub struct GenerateArgs {
#[clap(group = "abc", long = "id", value_name = "ID")]
id: Option<i64>,
#[clap(group = "abc", long = "regex", value_name = "REGEX")]
regex: Option<String>,
#[clap(
group = "abc",
long = "start-time",
required = true,
value_name = "STARTTIME",
)]
start_time: Option<i64>,
#[clap(
group = "abc",
long = "end-time",
value_name = "ENDTIME",
required = true,
)]
end_time: Option<i64>,
}
- run (This is responsible for executing stored in DB using params provided as argument)
#[derive(Args, Debug)]
#[clap(group(ArgGroup::new("qwerty").required(true).multiple(true)))]
pub struct RunArgs {
#[clap(group = "abc", long = "run-id", value_name = "RUNID")]
run_id: Option<i64>,
#[clap(group = "abc", long = "retry", value_name = "RETRY")]
retry: Option<i64>,
#[clap(
group = "abc",
long = "delay",
value_name = "DELAY",
)]
delay: Option<i64>,
}
I want to overload the behavior of the run
subcommand so that in addition to its own parameters, it can accept the same parameters of the generate
sub-command.
If the params of generate
sub-command are provided by users to the run
subcommand, the system would first generate item, store in DB & then execute the item.
Therefore the user can generate & run in a single command as opposed to two different commands if they should choose to do so.
Do I need to redefine all the parameters supported by generate
subcommand in run
subcommand? or is there a way to re-use the parameters? Re-using would help so that I don't need to maintain changes across the two subcommands.