add --fail-fast argument for responding to confirmations
This commit is contained in:
parent
b1d559ea00
commit
c11593e7e4
1 changed files with 42 additions and 6 deletions
48
src/main.rs
48
src/main.rs
|
@ -85,10 +85,15 @@ fn cli() -> App<'static, 'static> {
|
||||||
.about("Interactive interface for trade confirmations")
|
.about("Interactive interface for trade confirmations")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("accept-all")
|
Arg::with_name("accept-all")
|
||||||
.short("a")
|
.short("a")
|
||||||
.long("accept-all")
|
.long("accept-all")
|
||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.help("Accept all open trade confirmations. Does not open interactive interface.")
|
.help("Accept all open trade confirmations. Does not open interactive interface.")
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("fail-fast")
|
||||||
|
.takes_value(false)
|
||||||
|
.help("If submitting a confirmation response fails, exit immediately.")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
|
@ -409,22 +414,49 @@ fn run() -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut any_failed = false;
|
||||||
|
let fail_fast = trade_matches.is_present("fail-fast");
|
||||||
if trade_matches.is_present("accept-all") {
|
if trade_matches.is_present("accept-all") {
|
||||||
info!("accepting all confirmations");
|
info!("accepting all confirmations");
|
||||||
for conf in &confirmations {
|
for conf in &confirmations {
|
||||||
let result = account.accept_confirmation(conf);
|
let result = account.accept_confirmation(conf);
|
||||||
debug!("accept confirmation result: {:?}", result);
|
if result.is_err() {
|
||||||
|
warn!("accept confirmation result: {:?}", result);
|
||||||
|
any_failed = true;
|
||||||
|
if fail_fast {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debug!("accept confirmation result: {:?}", result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if termion::is_tty(&stdout()) {
|
if termion::is_tty(&stdout()) {
|
||||||
let (accept, deny) = tui::prompt_confirmation_menu(confirmations);
|
let (accept, deny) = tui::prompt_confirmation_menu(confirmations);
|
||||||
for conf in &accept {
|
for conf in &accept {
|
||||||
let result = account.accept_confirmation(conf);
|
let result = account.accept_confirmation(conf);
|
||||||
debug!("accept confirmation result: {:?}", result);
|
if result.is_err() {
|
||||||
|
warn!("accept confirmation result: {:?}", result);
|
||||||
|
any_failed = true;
|
||||||
|
if fail_fast {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debug!("accept confirmation result: {:?}", result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for conf in &deny {
|
for conf in &deny {
|
||||||
let result = account.deny_confirmation(conf);
|
let result = account.deny_confirmation(conf);
|
||||||
debug!("deny confirmation result: {:?}", result);
|
debug!("deny confirmation result: {:?}", result);
|
||||||
|
if result.is_err() {
|
||||||
|
warn!("deny confirmation result: {:?}", result);
|
||||||
|
any_failed = true;
|
||||||
|
if fail_fast {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debug!("deny confirmation result: {:?}", result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn!("not a tty, not showing menu");
|
warn!("not a tty, not showing menu");
|
||||||
|
@ -433,6 +465,10 @@ fn run() -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if any_failed {
|
||||||
|
error!("Failed to respond to some confirmations.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest.save(&passkey)?;
|
manifest.save(&passkey)?;
|
||||||
|
|
Loading…
Reference in a new issue