Skip to content

Commit

Permalink
Merge branch 'bat/feature/refactor-cli' (#1738)
Browse files Browse the repository at this point in the history
* bat/feature/refactor-cli:
  [feat]: Moved cli commands common to testing, cli, and sdk out into apps
  • Loading branch information
tzemanovic committed Jul 19, 2023
2 parents 1f18bf7 + ca154cd commit aff4d3c
Show file tree
Hide file tree
Showing 11 changed files with 820 additions and 229 deletions.
12 changes: 8 additions & 4 deletions apps/src/bin/namada-client/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod cli;

use color_eyre::eyre::Result;
use namada_apps::logging;
use namada_apps::cli::api::CliApi;
use namada_apps::facade::tendermint_rpc::HttpClient;
use namada_apps::{cli, logging};
use tracing_subscriber::filter::LevelFilter;

#[tokio::main]
Expand All @@ -13,5 +13,9 @@ async fn main() -> Result<()> {
let _log_guard = logging::init_from_env_or(LevelFilter::INFO)?;

// run the CLI
cli::main().await
CliApi::<()>::handle_client_command::<HttpClient>(
None,
cli::namada_client_cli()?,
)
.await
}
143 changes: 0 additions & 143 deletions apps/src/bin/namada-relayer/cli.rs

This file was deleted.

9 changes: 5 additions & 4 deletions apps/src/bin/namada-relayer/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod cli;

use color_eyre::eyre::Result;
use namada_apps::logging;
use namada::tendermint_rpc::HttpClient;
use namada_apps::cli::api::CliApi;
use namada_apps::{cli, logging};
use tracing_subscriber::filter::LevelFilter;

#[tokio::main]
Expand All @@ -12,6 +12,7 @@ async fn main() -> Result<()> {
// init logging
logging::init_from_env_or(LevelFilter::INFO)?;

let (cmd, _) = cli::namada_relayer_cli()?;
// run the CLI
cli::main().await
CliApi::<()>::handle_relayer_command::<HttpClient>(None, cmd).await
}
7 changes: 4 additions & 3 deletions apps/src/bin/namada-wallet/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
mod cli;
use color_eyre::eyre::Result;
use namada_apps::cli;
use namada_apps::cli::api::CliApi;

pub fn main() -> Result<()> {
color_eyre::install()?;

let (cmd, ctx) = cli::namada_wallet_cli()?;
// run the CLI
cli::main()
CliApi::<()>::handle_wallet_command(cmd, ctx)
}
4 changes: 4 additions & 0 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
//! client can be dispatched via `namada node ...` or `namada client ...`,
//! respectively.
pub mod api;
pub mod client;
pub mod context;
pub mod relayer;
mod utils;
pub mod wallet;

use clap::{ArgGroup, ArgMatches, ColorChoice};
use color_eyre::eyre::Result;
Expand Down
29 changes: 29 additions & 0 deletions apps/src/lib/cli/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::marker::PhantomData;

use namada::ledger::queries::Client;
use namada::ledger::rpc::wait_until_node_is_synched;
use namada::tendermint_rpc::HttpClient;
use namada::types::control_flow::Halt;
use tendermint_config::net::Address as TendermintAddress;

use crate::client::utils;

/// Trait for clients that can be used with the CLI.
#[async_trait::async_trait(?Send)]
pub trait CliClient: Client + Sync {
fn from_tendermint_address(address: &mut TendermintAddress) -> Self;
async fn wait_until_node_is_synced(&self) -> Halt<()>;
}

#[async_trait::async_trait(?Send)]
impl CliClient for HttpClient {
fn from_tendermint_address(address: &mut TendermintAddress) -> Self {
HttpClient::new(utils::take_config_address(address)).unwrap()
}

async fn wait_until_node_is_synced(&self) -> Halt<()> {
wait_until_node_is_synched(self).await
}
}

pub struct CliApi<IO>(PhantomData<IO>);
Loading

0 comments on commit aff4d3c

Please sign in to comment.