Display help on missing args

This commit is contained in:
clerie 2024-12-25 15:48:57 +01:00
parent 6fd28effe5
commit 43c1de727a

View File

@ -31,6 +31,7 @@ use log::{
use tokio_serial; use tokio_serial;
#[derive(Subcommand, Clone)] #[derive(Subcommand, Clone)]
#[command(arg_required_else_help = true)]
enum DeviceCommands { enum DeviceCommands {
/// Request current state /// Request current state
State, State,
@ -52,6 +53,7 @@ impl Default for DeviceCommands {
} }
#[derive(Subcommand, Clone)] #[derive(Subcommand, Clone)]
#[command(arg_required_else_help = true)]
enum Commands { enum Commands {
/// List available serial devices /// List available serial devices
ListDevices, ListDevices,
@ -68,7 +70,7 @@ enum Commands {
} }
#[derive(Parser)] #[derive(Parser)]
#[command(version, about, long_about = None)] #[command(version, about, long_about = None, arg_required_else_help = true)]
struct Cli { struct Cli {
#[command(subcommand)] #[command(subcommand)]
command: Option<Commands>, command: Option<Commands>,
@ -112,10 +114,7 @@ async fn main() -> Result<()>{
let cli = Cli::parse(); let cli = Cli::parse();
let command: Commands = match &cli.command { let command = &cli.command.context("No command provided")?.clone();
Some(command) => command.clone(),
None => Commands::ListDevices,
};
match &command { match &command {
Commands::ListDevices => { Commands::ListDevices => {