diff --git a/ant-cli/src/commands.rs b/ant-cli/src/commands.rs index ff065a06c0..35985fe7b1 100644 --- a/ant-cli/src/commands.rs +++ b/ant-cli/src/commands.rs @@ -12,7 +12,7 @@ mod vault; mod wallet; use crate::opt::Opt; -use clap::Subcommand; +use clap::{error::ErrorKind, CommandFactory as _, Subcommand}; use color_eyre::Result; #[derive(Subcommand, Debug)] @@ -230,6 +230,11 @@ pub async fn handle_subcommand(opt: Opt) -> Result<()> { WalletCmd::Export => wallet::export(), WalletCmd::Balance => wallet::balance().await, }, - None => Ok(()), + None => { + // If no subcommand is given, default to clap's error behaviour. + Opt::command() + .error(ErrorKind::MissingSubcommand, "Please provide a subcommand") + .exit(); + } } } diff --git a/ant-cli/src/opt.rs b/ant-cli/src/opt.rs index 9d7e4edd9b..c437829b2b 100644 --- a/ant-cli/src/opt.rs +++ b/ant-cli/src/opt.rs @@ -19,7 +19,7 @@ use std::time::Duration; #[command(disable_version_flag = true)] #[command(author, version, about, long_about = None)] pub(crate) struct Opt { - /// Available sub commands. + // Available subcommands. This is optional to allow `--version` to work without a subcommand. #[clap(subcommand)] pub command: Option,