Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multiple values of an argument in Clap

Tags:

rust

clap

I am using Clap and my YAML file has the following:

args:
- DIRECTORY
    help: one or more directories
    required: true
    multiple: true

In my main.rs, I want to get the name of each of the directory passed as an argument and do something like

dir_names.push(name_of_the_directory);

where dir_names is a vector and name_of_the_directory is a string slice.

How do I proceed?

like image 282
ka s Avatar asked Nov 16 '25 20:11

ka s


1 Answers

You can do it by using the values_of method:

let dir_names: Vec<&str> = m.values_of("output").unwrap().collect();

In current version of clap (4.4.7), this has been replaced by get_many:

let dir_names: Vec<&str> = m.get_many ("output").unwrap().collect();
like image 176
Jmb Avatar answered Nov 18 '25 21:11

Jmb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!