You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using clap derive for a cli like cli user <USER> <COMMAND>, for the following (derive) code
use clap::{Args,Parser,Subcommand};#[derive(Parser)]#[command(version, about, long_about = None)]#[command(propagate_version = true)]structCli{#[command(subcommand)]command:Commands,}#[derive(Subcommand)]enumCommands{User(UserArgs),}#[derive(Args)]structUserArgs{/// User identifieruser:String,#[clap(subcommand)]command:UserSubCommands,}#[derive(Subcommand)]enumUserSubCommands{/// Display userDisplay,/// Delete userDelete,}fnmain(){let _ = Cli::parse();}
If the user does not provide the username, we have the "pretty exit" :
$ cliq user
Usage: cliq user <USER> <COMMAND>
Commands:
display Display user
delete Delete user
help Print this message or the help of the given subcommand(s)
Arguments:
<USER> User identifier
Options:
-h, --help Print help
-V, --version Print version
With the username and help subcommand, we also have the "pretty exit" :
$ cliq user toto help
Usage: cliq user <USER> <COMMAND>
Commands:
display Display user
...
But if the user is provided, but not the command, the not so pretty "error exit" is provided
$ cliq user toto
error: 'cliq user' requires a subcommand but one was not provided
[subcommands: display, delete, help]
Usage: cliq user <USER> <COMMAND>
For more information, try '--help'.
Hence my question : **how can we display the "pretty exit" instead of "error exit" in this case ? (i tried arg_required_else_help, subcommand_required on every possible location, but no success...)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Using clap derive for a cli like
cli user <USER> <COMMAND>
, for the following (derive) codeIf 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
arg_required_else_help
,subcommand_required
on every possible location, but no success...)Thank you !!
Beta Was this translation helpful? Give feedback.
All reactions