在 Clap 中使用一个参数的多个值

Using multiple values of an argument in Clap

我正在使用 Clap,我的 YAML 文件包含以下内容:

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

在我的 main.rs 中,我想获取作为参数传递的每个目录的名称并执行类似

的操作
dir_names.push(name_of_the_directory);

其中 dir_names 是一个向量,name_of_the_directory 是一个字符串切片。

我该如何继续?

您可以使用values_of方法来完成:

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