How to specify about text for subcommands? #1619
-
Clarification Request / Bug Report ?I am using the annotations and they mostly work fine. However, when I try to follow the example and use below code, the subcommand does not get any explaining text in the help section. #[derive(Clap)]
enum SubCommand {
Test(Test),
}
/// A subcommand for controlling testing
#[derive(Clap)]
#[clap(name = "test", version = "1.3", author = "Someone Else")]
struct Test {
/// Print debug info
#[clap(short = "d")]
debug: bool
} Rust Version$ rustc -V
rustc 1.40.0 (73528e339 2019-12-16) Affected Version of clap$ grep clap cli/Cargo.toml
clap = { git = "https://github.com/clap-rs/clap.git", rev = "f402f7a", features = ["color", "suggestions", "derive"] } Expected Behavior SummaryI would expect the Actual Behavior SummaryThe only subcommand that gets any explanation is
Perhaps related: The version at the start of the help message Steps to Reproduce the issueCargo.toml: [package]
name = "debugcli"
version = "0.1.0"
authors = ["Eric Mink <eric@mink.li>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { git = "https://github.com/clap-rs/clap.git", rev = "f402f7a", features = ["color", "suggestions", "derive"] }
[workspace] src/main.rs: extern crate clap;
use clap::*;
/// This doc string acts as a help message when the user runs '--help'
/// as do all doc strings on fields
#[derive(Clap)]
#[clap(
version = "1.0",
author = "LucidBrot",
name = "name",
about = "about"
)]
struct Opts {
#[clap(subcommand)]
subcmd: SubCommand,
}
#[derive(Clap)]
enum SubCommand {
Test(Test),
}
/// A subcommand for controlling testing
#[derive(Clap)]
#[clap(name = "test", version = "1.3", author = "Someone Else", about = "about text")]
struct Test {
/// Print debug info
#[clap(short = "d")]
debug: bool
}
fn main() {
let opts: Opts = Opts::parse();
// You can handle information about subcommands by requesting their matches by name
// (as below), requesting just the name used, or both at the same time
match opts.subcmd {
SubCommand::Test(t) => (),
}
// more program logic goes here...
} Debug outputCompile clap with cargo features [dependencies]
clap = { git = "https://github.com/clap-rs/clap.git", rev = "f402f7a", features = ["debug", "color", "suggestions", "derive"] } Debug Output
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Doc comments for subcommands must be placed on the corresponding enum variant (the same for #[derive(Clap)]
enum SubCommand {
/// A subcommand for controlling testing
Test(Test),
}
#[derive(Clap)]
#[clap(name = "test", version = "1.3", author = "Someone Else")]
struct Test {
/// Print debug info
#[clap(short = "d")]
debug: bool
} |
Beta Was this translation helpful? Give feedback.
-
Thank you very much! I created a PR so other people like me will have it easier in the future. |
Beta Was this translation helpful? Give feedback.
-
I think this is resolved now. Feel free to reopen if you disagree. |
Beta Was this translation helpful? Give feedback.
Doc comments for subcommands must be placed on the corresponding enum variant (the same for
structopt
).