-
Make sure you completed the following tasks
Describe your use caseI'm trying to make Clap ignore certain subcommands in my Describe the solution you'd likeI'd like there to be a #[derive(Clap)]
pub struct Opt {
#[clap(short, long, parse(from_occurrences))]
pub verbose: i32,
// ...
#[clap(subcommand)]
SubCommand(SubCommand),
}
#[derive(Clap)]
pub enum SubCommand {
#[clap(name = "run")]
Run(RunCommand),
#[clap(name = "build")]
Build(BuildCommand),
#[clap(name = "check")]
Check(CheckCommand),
#[clap(hidden)] // <---- addition
Lib(LibCommand),
}
#[derive(Clap)]
pub struct RunCommand {
/// Path to main file
#[clap(parse(from_os_str), name = "main")]
pub main: Option<PathBuf>,
}
// ...
pub struct LibCommand {
/// Input source string.
pub source: String,
} I thought it was already possible, but I get Alternatives, if applicableMy current alternative is to use configure with #[cfg_attr(feature = "cli", derive(Clap))]
pub enum SubCommand {
#[cfg_attr(feature = "cli", clap(name = "run"))]
Run(RunCommand),
#[cfg_attr(feature = "cli", clap(name = "build"))]
Build(BuildCommand),
#[cfg_attr(feature = "cli", clap(name = "check"))]
Check(CheckCommand),
#[cfg(feature = "lib")]
Lib(LibCommand),
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Try |
Beta Was this translation helpful? Give feedback.
-
If you stumble upon this discussion and are using a newer version of Clap (~ 4.0), here's how to do it: #[derive(Subcommand)]
pub enum SubCommand {
// ...
#[command(hide = true)]
Lib(LibCommand),
} |
Beta Was this translation helpful? Give feedback.
Try
#[clap(setting = AppSettings::Hidden)]
. The error you are getting is correct becausehidden
does not exist forclap::App