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

Move CLI logic into apps/lib #1738

Merged
merged 5 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
461 changes: 0 additions & 461 deletions apps/src/bin/namada-client/cli.rs

This file was deleted.

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