[英]How to provide multiple line help message with Clap?
Is there a way for us to have line breaks in clap's help message?有没有办法让我们在 clap 的帮助信息中换行?
I tried multiple line comments, also tried inserting \n
in the mix.我尝试了多行注释,还尝试在混合中插入
\n
。 But neither works.但两者都不起作用。
#[derive(Parser, Debug)]
#[clap(author, version, about)]
struct Args {
/// The input filename.\n
/// Hello world!
#[clap(short, long, value_parser)]
input: String,
}
Output:输出:
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
Is there away to achieve the following?有没有实现以下目标?
USAGE:
ascii_tree --input <INPUT>
OPTIONS:
-h, --help Print help information
-i, --input <INPUT> The input filename.
Hello world!
-V, --version Print version information
I know of two options.我知道两种选择。 Make the second line only contain
///
, or use verbatim_doc_comment
:使第二行仅包含
///
,或使用verbatim_doc_comment
:
#[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,
}
You can add the verbatim_doc_comment
option:您可以添加
verbatim_doc_comment
选项:
#[derive(Parser, Debug)]
#[clap(author, version, about)]
struct Args {
/// The input filename.
/// Hello world!
#[clap(short, long, value_parser, verbatim_doc_comment)]
input: String,
}
USAGE:
ascii_tree --input <INPUT>
OPTIONS:
-h, --help Print help information
-i, --input <INPUT> The input filename.
Hello world!
-V, --version Print version information
It seems without it, Rust only recognizes paragraph breaks via double-newline.似乎没有它,Rust 只能通过双换行符识别段落中断。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.