clap
clap copied to clipboard
Hidden subcommands shown when "requires a subcommand but one was not provided"
Please complete the following tasks
- [X] I have searched the discussions
- [X] I have searched the open and rejected issues
Rust Version
rustc 1.74.0 (79e9716c9 2023-11-13)
Clap Version
4.5.4
Minimal reproducible code
use clap::{Parser, Subcommand};
#[derive(Parser, Debug)]
#[clap(version, about)]
struct Cli {
#[clap(subcommand)]
command: Command,
#[clap(long)]
message: String,
}
#[derive(Subcommand, Debug)]
enum Command {
Hello,
#[clap(hide = true)]
Secret, // <------ This subcommand is marked hidden and shouldn't be suggested to the user
}
fn main() {
let cli = Cli::parse();
match cli.command {
Command::Hello => println!("Hello {}", cli.message),
Command::Secret => println!("Secret {}", cli.message),
}
}
Steps to reproduce the bug with the above code
$ cargo run -- --message foo
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
Running `target/debug/clap-repro --message foo`
error: 'clap-repro' requires a subcommand but one was not provided
[subcommands: hello, secret, help]
Usage: clap-repro --message <MESSAGE> <COMMAND>
For more information, try '--help'.
Actual Behaviour
The problem is that the secret
subcommand is marked as hidden, yet it is suggested as one of the possible subcommands in the list [subcommands: hello, secret, help]
Expected Behaviour
Since the secret
subcommand is marked as hidden, it should not be suggested to the user in the list of possible subcommands. So
Actual: [subcommands: hello, secret, help]
Expected: [subcommands: hello, help]
Additional Context
The --message
flag in the repro case seems to be important. If I remove it and omit the subcommand, it sees that no arguments are provided and simply displays the normal help message, which correctly omits the hidden subcommand.
Debug Output
No response