0

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.

alwaysAStudent
  • 2,110
  • 4
  • 24
  • 47
  • It's unclear how your example command matches up with the example format at the top of your question. Please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – PitaJ May 22 '23 at 18:03
  • @PitaJ updated the description to provide additional info without sharing too much internal code. let me know if that provides more insights. – alwaysAStudent May 22 '23 at 18:21
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/253775/discussion-between-cafce25-and-alwaysastudent). – cafce25 May 22 '23 at 19:28

0 Answers0