首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用Clap提供多行帮助信息?

如何用Clap提供多行帮助信息?
EN

Stack Overflow用户
提问于 2022-07-20 10:55:14
回答 2查看 322关注 0票数 1

有什么办法让我们在“鼓掌”的帮助信息中出现断线吗?

我尝试了多行注释,也尝试在混合中插入\n。但这两样都不管用。

代码语言:javascript
复制
#[derive(Parser, Debug)]
#[clap(author, version, about)]
struct Args {
    /// The input filename.\n
    /// Hello world!
    #[clap(short, long, value_parser)]
    input: String,
}

输出:

代码语言:javascript
复制
USAGE:
    ascii_tree --input <INPUT>

OPTIONS:
    -h, --help             Print help information
    -i, --input <INPUT>    The input filename.\n Hello world!
    -V, --version          Print version information

是否有办法实现以下目标?

代码语言:javascript
复制
USAGE:
    ascii_tree --input <INPUT>

OPTIONS:
    -h, --help             Print help information
    -i, --input <INPUT>    The input filename.
                           Hello world!
    -V, --version          Print version information
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-07-20 11:07:28

我知道有两个选择。使第二行只包含///,或使用verbatim_doc_comment

代码语言:javascript
复制
#[derive(Parser, Debug)]
struct Args {
    /// Name of the person to greet
    ///
    /// Has a multi-line help.
    #[clap(short, long)]
    name: String,

    /// Number of times to greet
    /// Use the verbatim arg
    #[clap(short, long, verbatim_doc_comment)]
    count: u8,
}

游乐场

票数 3
EN

Stack Overflow用户

发布于 2022-07-20 11:17:34

您可以添加verbatim_doc_comment选项:

代码语言:javascript
复制
#[derive(Parser, Debug)]
#[clap(author, version, about)]
struct Args {
    /// The input filename.
    /// Hello world!
    #[clap(short, long, value_parser, verbatim_doc_comment)]
    input: String,
}
代码语言:javascript
复制
USAGE:
    ascii_tree --input <INPUT>

OPTIONS:
    -h, --help             Print help information
    -i, --input <INPUT>    The input filename.
                           Hello world!
    -V, --version          Print version information

似乎没有它,Rust只通过双换行符识别段落。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73050387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档