Skip to content

Commit

Permalink
feat(ant-cli): show usage without arguments
Browse files Browse the repository at this point in the history
When no subcommand is passed, show the usage and error the CLI.
  • Loading branch information
b-zee committed Jan 6, 2025
1 parent 246638f commit 2c8b9c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions ant-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ 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 } => {
file::download(&addr, &dest_file, peers.await?).await
}
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 {
Expand All @@ -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,
Expand All @@ -230,6 +230,5 @@ pub async fn handle_subcommand(opt: Opt) -> Result<()> {
WalletCmd::Export => wallet::export(),
WalletCmd::Balance => wallet::balance().await,
},
None => Ok(()),
}
}
2 changes: 1 addition & 1 deletion ant-cli/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::time::Duration;
pub(crate) struct Opt {
/// Available sub commands.
#[clap(subcommand)]
pub command: Option<SubCmd>,
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<Duration> { Ok(t.parse().map(Duration::from_secs)?) })]
Expand Down

0 comments on commit 2c8b9c2

Please sign in to comment.