-
Using clap derive for a cli like use clap::{Args, Parser, Subcommand};
#[derive(Parser)]
#[command(version, about, long_about = None)]
#[command(propagate_version = true)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
User(UserArgs),
}
#[derive(Args)]
struct UserArgs {
/// User identifier
user: String,
#[clap(subcommand)]
command: UserSubCommands,
}
#[derive(Subcommand)]
enum UserSubCommands {
/// Display user
Display,
/// Delete user
Delete,
}
fn main() {
let _ = Cli::parse();
} If the user does not provide the username, we have the "pretty exit" :
With the username and help subcommand, we also have the "pretty exit" :
But if the user is provided, but not the command, the not so pretty "error exit" is provided
Hence my question : **how can we display the "pretty exit" instead of "error exit" in this case ? (i tried Thank you !! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There used to be a setting This was done for a couple of reasons
|
Beta Was this translation helpful? Give feedback.
There used to be a setting
SubcommandRequiredElseHelp
which was removed in favor of separatearg_required_else_help
(if any type of arg is present, no help is shown) andsubcommand_required
.This was done for a couple of reasons