繁体   English   中英

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

[英]How to provide multiple line help message with Clap?

有没有办法让我们在 clap 的帮助信息中换行?

我尝试了多行注释,还尝试在混合中插入\n 但两者都不起作用。

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

输出:

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

有没有实现以下目标?

USAGE:
    ascii_tree --input <INPUT>

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

我知道两种选择。 使第二行仅包含/// ,或使用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,
}

操场

您可以添加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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM