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

UX improvement in relayer #541

Merged
merged 13 commits into from
Jan 21, 2021
9 changes: 3 additions & 6 deletions relayer-cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use abscissa_core::{Command, Options, Runnable};
use serde_json::json;

use relayer::config::Config;
use relayer::keys::add::{add_key, KeysAddOptions};
Expand Down Expand Up @@ -49,18 +48,16 @@ impl Runnable for KeysAddCmd {

let opts = match self.validate_options(&config) {
Err(err) => {
return Output::with_error().with_result(json!(err)).exit();
return Output::error(err).exit();
}
Ok(result) => result,
};

let res: Result<String, Error> = add_key(opts).map_err(|e| Kind::Keys.context(e).into());

match res {
Ok(r) => Output::with_success().with_result(json!(r)).exit(),
Err(e) => Output::with_error()
.with_result(json!(format!("{}", e)))
.exit(),
Ok(r) => Output::success(r).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
}
}
}
9 changes: 3 additions & 6 deletions relayer-cli/src/commands/keys/list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use abscissa_core::{Command, Options, Runnable};
use serde_json::json;

use relayer::config::Config;
use relayer::keys::list::{list_keys, KeysListOptions};
Expand Down Expand Up @@ -39,18 +38,16 @@ impl Runnable for KeysListCmd {

let opts = match self.validate_options(&config) {
Err(err) => {
return Output::with_error().with_result(json!(err)).exit();
return Output::error(err).exit();
}
Ok(result) => result,
};

let res: Result<String, Error> = list_keys(opts).map_err(|e| Kind::Keys.context(e).into());

match res {
Ok(r) => Output::with_success().with_result(json!(r)).exit(),
Err(e) => Output::with_error()
.with_result(json!(format!("{}", e)))
.exit(),
Ok(r) => Output::success(r).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
}
}
}
9 changes: 3 additions & 6 deletions relayer-cli/src/commands/keys/restore.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use abscissa_core::{Command, Options, Runnable};
use serde_json::json;

use relayer::config::Config;
use relayer::keys::restore::{restore_key, KeysRestoreOptions};
Expand Down Expand Up @@ -57,7 +56,7 @@ impl Runnable for KeyRestoreCmd {

let opts = match self.validate_options(&config) {
Err(err) => {
return Output::with_error().with_result(json!(err)).exit();
return Output::error(err).exit();
}
Ok(result) => result,
};
Expand All @@ -66,10 +65,8 @@ impl Runnable for KeyRestoreCmd {
restore_key(opts).map_err(|e| Kind::Keys.context(e).into());

match res {
Ok(r) => Output::with_success().with_result(json!(r)).exit(),
Err(e) => Output::with_error()
.with_result(json!(format!("{}", e)))
.exit(),
Ok(r) => Output::success(r).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
}
}
}
8 changes: 1 addition & 7 deletions relayer-cli/src/commands/light/rm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{io, io::Write, ops::Deref};

use abscissa_core::{application::fatal_error, error::BoxError, Command, Options, Runnable};
use serde_json::json;
use tendermint_light_client::types::PeerId;

use ibc::ics24_host::identifier::ChainId;
Expand Down Expand Up @@ -108,12 +107,7 @@ impl RmCmd {
let config_path = crate::config::config_path()?;
relayer::config::store(&config, config_path)?;

Output::with_success()
.with_result(json!(format!(
"Removed light client peer(s) '{:?}'",
rmd_peers
)))
.exit();
Output::success(format!("Removed light client peer(s) '{:?}'", rmd_peers)).exit();

Ok(())
}
Expand Down
9 changes: 3 additions & 6 deletions relayer-cli/src/commands/query/channel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Arc;

use abscissa_core::{Command, Options, Runnable};
use serde_json::json;
use tendermint_proto::Protobuf;
use tokio::runtime::Runtime as TokioRuntime;

Expand Down Expand Up @@ -86,7 +85,7 @@ impl Runnable for QueryChannelEndCmd {

let (chain_config, opts) = match self.validate_options(&config) {
Err(err) => {
return Output::with_error().with_result(json!(err)).exit();
return Output::error(err).exit();
}
Ok(result) => result,
};
Expand All @@ -111,10 +110,8 @@ impl Runnable for QueryChannelEndCmd {
});

match res {
Ok(ce) => Output::with_success().with_result(json!(ce)).exit(),
Err(e) => Output::with_error()
.with_result(json!(format!("{}", e)))
.exit(),
Ok(ce) => Output::success(ce).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
}
}
}
Expand Down
25 changes: 9 additions & 16 deletions relayer-cli/src/commands/query/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Arc;

use abscissa_core::{Command, Options, Runnable};
use serde_json::json;
use tendermint_proto::Protobuf;
use tokio::runtime::Runtime as TokioRuntime;
use tracing::info;
Expand Down Expand Up @@ -72,7 +71,7 @@ impl Runnable for QueryClientStateCmd {

let (chain_config, opts) = match self.validate_options(&config) {
Err(err) => {
return Output::with_error().with_result(json!(err)).exit();
return Output::error(err).exit();
}
Ok(result) => result,
};
Expand All @@ -89,10 +88,8 @@ impl Runnable for QueryClientStateCmd {
AnyClientState::decode_vec(&v.value).map_err(|e| Kind::Query.context(e).into())
});
match res {
Ok(cs) => Output::with_success().with_result(json!(cs)).exit(),
Err(e) => Output::with_error()
.with_result(json!(format!("{}", e)))
.exit(),
Ok(cs) => Output::success(cs).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
}
}
}
Expand Down Expand Up @@ -166,7 +163,7 @@ impl Runnable for QueryClientConsensusCmd {

let (chain_config, opts) = match self.validate_options(&config) {
Err(err) => {
return Output::with_error().with_result(json!(err)).exit();
return Output::error(err).exit();
}
Ok(result) => result,
};
Expand All @@ -192,10 +189,8 @@ impl Runnable for QueryClientConsensusCmd {
});

match res {
Ok(cs) => Output::with_success().with_result(json!(cs)).exit(),
Err(e) => Output::with_error()
.with_result(json!(format!("{}", e)))
.exit(),
Ok(cs) => Output::success(cs).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
}
}
}
Expand Down Expand Up @@ -277,7 +272,7 @@ impl Runnable for QueryClientConnectionsCmd {

let (chain_config, opts) = match self.validate_options(&config) {
Err(err) => {
return Output::with_error().with_result(json!(err)).exit();
return Output::error(err).exit();
}
Ok(result) => result,
};
Expand All @@ -295,10 +290,8 @@ impl Runnable for QueryClientConnectionsCmd {
});

match res {
Ok(cs) => Output::with_success().with_result(json!(cs)).exit(),
Err(e) => Output::with_error()
.with_result(json!(format!("{}", e)))
.exit(),
Ok(cs) => Output::success(cs).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
}
}
}
Expand Down
17 changes: 6 additions & 11 deletions relayer-cli/src/commands/query/connection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Arc;

use abscissa_core::{Command, Options, Runnable};
use serde_json::json;
use tokio::runtime::Runtime as TokioRuntime;

use ibc::ics03_connection::connection::ConnectionEnd;
Expand Down Expand Up @@ -75,7 +74,7 @@ impl Runnable for QueryConnectionEndCmd {

let (chain_config, opts) = match self.validate_options(&config) {
Err(err) => {
return Output::with_error().with_result(json!(err)).exit();
return Output::error(err).exit();
}
Ok(result) => result,
};
Expand All @@ -91,10 +90,8 @@ impl Runnable for QueryConnectionEndCmd {
.map_err(|e| Kind::Query.context(e).into());

match res {
Ok(ce) => Output::with_success().with_result(json!(ce)).exit(),
Err(e) => Output::with_error()
.with_result(json!(format!("{}", e)))
.exit(),
Ok(ce) => Output::success(ce).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
}
}
}
Expand Down Expand Up @@ -148,7 +145,7 @@ impl Runnable for QueryConnectionChannelsCmd {

let (chain_config, opts) = match self.validate_options(&config) {
Err(err) => {
return Output::with_error().with_result(json!(err)).exit();
return Output::error(err).exit();
}
Ok(result) => result,
};
Expand All @@ -167,10 +164,8 @@ impl Runnable for QueryConnectionChannelsCmd {
.map_err(|e| Kind::Query.context(e).into());

match res {
Ok(cids) => Output::with_success().with_result(json!(cids)).exit(),
Err(e) => Output::with_error()
.with_result(json!(format!("{}", e)))
.exit(),
Ok(cids) => Output::success(cids).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
}
}
}
Expand Down
Loading