Skip to content

Commit

Permalink
Merge branch 'bat/feature/refactor-cli' (#1738)
Browse files Browse the repository at this point in the history
* origin/bat/feature/refactor-cli:
  channgelog: add #1738
  [feat]: Moved cli commands common to testing, cli, and sdk out into apps
  • Loading branch information
Fraccaman committed Jul 22, 2023
2 parents e956a37 + 7213235 commit f576989
Show file tree
Hide file tree
Showing 11 changed files with 865 additions and 228 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/miscellaneous/1738-refactor-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Refactored CLI into libraries for future re-use in integration tests and
to enable generic IO. ([\#1738](https://github.com/anoma/namada/pull/1738))
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 f576989

Please sign in to comment.