Skip to content

Commit

Permalink
refactor(ant-cli): error when no subcommand given
Browse files Browse the repository at this point in the history
  • Loading branch information
b-zee committed Jan 6, 2025
1 parent 246638f commit 463b706
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions ant-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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::InvalidSubcommand, "No subcommand given")
.exit();
}
}
}
2 changes: 1 addition & 1 deletion ant-cli/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubCmd>,

Expand Down

0 comments on commit 463b706

Please sign in to comment.