From 2c8b9c2d63666230b4eaec47184f94cf691751b8 Mon Sep 17 00:00:00 2001 From: Benno Zeeman Date: Mon, 6 Jan 2025 15:48:46 +0100 Subject: [PATCH] feat(ant-cli): show usage without arguments When no subcommand is passed, show the usage and error the CLI. --- ant-cli/src/commands.rs | 9 ++++----- ant-cli/src/opt.rs | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ant-cli/src/commands.rs b/ant-cli/src/commands.rs index ff065a06c0..6c6316d3cd 100644 --- a/ant-cli/src/commands.rs +++ b/ant-cli/src/commands.rs @@ -187,7 +187,7 @@ pub async fn handle_subcommand(opt: Opt) -> Result<()> { let cmd = opt.command; match cmd { - Some(SubCmd::File { command }) => match command { + SubCmd::File { command } => match command { FileCmd::Cost { file } => file::cost(&file, peers.await?).await, FileCmd::Upload { file, public } => file::upload(&file, public, peers.await?).await, FileCmd::Download { addr, dest_file } => { @@ -195,7 +195,7 @@ pub async fn handle_subcommand(opt: Opt) -> Result<()> { } FileCmd::List => file::list(), }, - Some(SubCmd::Register { command }) => match command { + SubCmd::Register { command } => match command { RegisterCmd::GenerateKey { overwrite } => register::generate_key(overwrite), RegisterCmd::Cost { name } => register::cost(&name, peers.await?).await, RegisterCmd::Create { @@ -211,13 +211,13 @@ pub async fn handle_subcommand(opt: Opt) -> Result<()> { RegisterCmd::Get { address, name } => register::get(address, name, peers.await?).await, RegisterCmd::List => register::list(), }, - Some(SubCmd::Vault { command }) => match command { + SubCmd::Vault { command } => match command { VaultCmd::Cost => vault::cost(peers.await?).await, VaultCmd::Create => vault::create(peers.await?).await, VaultCmd::Load => vault::load(peers.await?).await, VaultCmd::Sync { force } => vault::sync(peers.await?, force).await, }, - Some(SubCmd::Wallet { command }) => match command { + SubCmd::Wallet { command } => match command { WalletCmd::Create { no_password, password, @@ -230,6 +230,5 @@ pub async fn handle_subcommand(opt: Opt) -> Result<()> { WalletCmd::Export => wallet::export(), WalletCmd::Balance => wallet::balance().await, }, - None => Ok(()), } } diff --git a/ant-cli/src/opt.rs b/ant-cli/src/opt.rs index 9d7e4edd9b..cee3a0934d 100644 --- a/ant-cli/src/opt.rs +++ b/ant-cli/src/opt.rs @@ -21,7 +21,7 @@ use std::time::Duration; pub(crate) struct Opt { /// Available sub commands. #[clap(subcommand)] - pub command: Option, + pub command: SubCmd, /// The maximum duration to wait for a connection to the network before timing out. #[clap(long = "timeout", global = true, value_parser = |t: &str| -> Result { Ok(t.parse().map(Duration::from_secs)?) })]