Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ant-cli): show usage without arguments #2601

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::MissingSubcommand, "Please provide a subcommand")
.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
Loading