gpt4 book ai didi

rust - 如何使用 Clap 提供多行帮助消息?

转载 作者:行者123 更新时间:2023-12-05 09:01:35 24 4
gpt4 key购买 nike

有没有办法让我们在 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,
}

Playground

关于rust - 如何使用 Clap 提供多行帮助消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73050387/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com