【问题标题】:How to pass special characters as string argument using structopt?如何使用structopt将特殊字符作为字符串参数传递?
【发布时间】:2020-04-28 02:24:22
【问题描述】:

我有一个命令行来搜索文件中的单词。我正在使用 StructOpt 来获取用户想要搜索的单词。

#[derive(Debug, StructOpt)]
pub struct Command {
    pub word_to_search: Option<String>,
}

当你写像command -a 这样的东西时,问题就来了。我知道图书馆正在尝试使用-a 做某事,而struct 中没有-a,所以我尝试了:command "-a",但它显示:

error: Found argument '-a' which wasn't expected, or isn't valid in this context

有没有办法使用 StructOpt 传递 -a 等特殊字符并检索信息 (-a)?

【问题讨论】:

    标签: rust structopt


    【解决方案1】:

    您无需更改任何内容,只需使用command -- -a 调用命令即可。双破折号用于表示它是选项的结尾,在这种情况下,其余的是用户正在寻找的单词。

    【讨论】:

      猜你喜欢
      • 2018-03-29
      • 2020-04-05
      • 1970-01-01
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      相关资源
      最近更新 更多