I am using rust clap (Version: 3.2.25) to parse and validate command line input to script I am developing. One of the inputs would be list of pair of start & end dates (in epoch format)
e.g.
[(123,345) (346,567) (658,857)]
I am currently trying the following:
#[derive(Subcommand, Debug)]
pub enum TestCommands {
/// Update registration.
Register(CommandRegisterArgs),
}
impl BackfillPlanCommands {
TestCommands::Register(args) => Box::new(
actions::CommandsRegisterBuilder::default()
.dates(args.dates.clone())
.build()
.expect("CommandsRegisterBuilder"),
),
}
#[derive(Args, Debug)]
pub struct CommandRegisterArgs {
/// Timestamp Range List
#[clap(
long = "times",
multiple_values = true,
required = true,
value_name = "TIMES"
)]
times: Vec<(i64, i64)>,
}
pub struct CommandRegister {
plan_id: i64,
dates: Vec<(i64, i64)>,
}
#[async_trait]
impl Action for CommandRegister {
async fn run(&self, ctx: &Context) -> Result<Box<dyn Output>> {
// Yet to Implement
return output_message(format!(
"Provided Times : {:?}.",
self.times
));
//return Err(Error::msg("Not implemented!"))
}
}
and attempt to execute the command as following:
testcommand register --dates 123,456 457,789
I get the following error:
dates: Vec<(i64, i64)>,
| ^^^^^ the trait `FromStr` is not implemented for `(i64, i64)`
AFAIK, rust clap does not directly support vector of vectors/tuples/arrays. Any suggestions on how to declare this and format in which to invoke? One constraint I have is to not use comma as delimiter in outer-vector. Comma might be acceptable between the start & end date.