你需要设置
subcommand_value_name = "action"
在
#[command]
:
use clap::{Parser, Subcommand};
#[derive(Debug, Parser)]
#[command(
author,
version,
about,
long_about = "Frobnicate the fizzbuzz",
subcommand_value_name = "action"
)]
struct Args {
#[arg(index = 1, name = "xml_file", help = "The base XML file to operate on")]
file: String,
#[command(subcommand, name = "action")]
action: Action,
}
#[derive(Clone, Debug, Subcommand)]
pub enum Action {
#[command(long_about = "Add a new type")]
Add,
#[command(long_about = "Display the selected type's properties")]
Find,
}
fn main() {
Args::parse();
}
输出:
Usage: playground <xml_file> <action>
Commands:
add Add a new type
find Display the selected type's properties
help Print this message or the help of the given subcommand(s)
Arguments:
<xml_file> The base XML file to operate on
Options:
-h, --help Print help (see more with '--help')
-V, --version Print version
Playground
您可以更改
Commands:
在的帮助消息中
Actions:
具有
subcommand_help_heading
:
#[command(
author,
version,
about,
long_about = "Frobnicate the fizzbuzz",
subcommand_help_heading = "Actions",
subcommand_value_name = "action"
)]
输出:
Usage: playground <xml_file> <action>
Actions:
add Add a new type
find Display the selected type's properties
help Print this message or the help of the given subcommand(s)
Arguments:
<xml_file> The base XML file to operate on
Options:
-h, --help Print help (see more with '--help')
-V, --version Print version