mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-02-02 10:35:22 -05:00
CLI --help
and --version
are handled correctly
Since we introduced our own parsing function for command line arguments, we have to make sure that clap's behaviour is handled correctly. Clap's `get_matches_from_safe` returns an error of a certain kind, of which `ErrorKind::HelpDisplayed` and `ErrorKind::VersionDisplayed ` have to be handled to properly print the help/version and exit the program. The clap error includes the message, so we print help/version in main now and ensure the program exits with `0` afterwards.
This commit is contained in:
parent
014388bfaa
commit
9ff29ae491
@ -20,6 +20,8 @@ use std::future::Future;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use structopt::clap;
|
||||||
|
use structopt::clap::ErrorKind;
|
||||||
use swap::bitcoin::TxLock;
|
use swap::bitcoin::TxLock;
|
||||||
use swap::cli::command::{parse_args_and_apply_defaults, Arguments, Command};
|
use swap::cli::command::{parse_args_and_apply_defaults, Arguments, Command};
|
||||||
use swap::database::Database;
|
use swap::database::Database;
|
||||||
@ -44,7 +46,23 @@ async fn main() -> Result<()> {
|
|||||||
data_dir,
|
data_dir,
|
||||||
debug,
|
debug,
|
||||||
cmd,
|
cmd,
|
||||||
} = parse_args_and_apply_defaults(env::args_os())?;
|
} = match parse_args_and_apply_defaults(env::args_os()) {
|
||||||
|
Ok(args) => args,
|
||||||
|
Err(e) => {
|
||||||
|
if let Some(clap_err) = e.downcast_ref::<clap::Error>() {
|
||||||
|
match clap_err.kind {
|
||||||
|
ErrorKind::HelpDisplayed | ErrorKind::VersionDisplayed => {
|
||||||
|
println!("{}", clap_err.message);
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
bail!(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bail!(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
match cmd {
|
match cmd {
|
||||||
Command::BuyXmr {
|
Command::BuyXmr {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user