diff --git a/src/cli/explorer.rs b/src/cli/explorer.rs index 3021190..c0bdd99 100644 --- a/src/cli/explorer.rs +++ b/src/cli/explorer.rs @@ -2,14 +2,22 @@ use bollard::models::{HostConfig, PortBinding}; use rand::distributions::Alphanumeric; use rand::Rng; +use clap::Args; use std::collections::HashMap; use crate::utils::docker::{container_exists, kill_container, run_docker_image}; -pub async fn explorer() { +#[derive(Args)] +pub struct ExplorerOpts { + #[clap(long, default_value = "localhost")] + pub host: String, +} + +pub async fn explorer(opts: &ExplorerOpts) { let random_string: String = (0..64).map(|_| rand::thread_rng().sample(Alphanumeric).to_string()).collect(); let secret_key_base = format!("SECRET_KEY_BASE={}", random_string); + let host_env = format!("PHX_HOST={}", opts.host); let env = vec![ "RPC_API_HOST=http://host.docker.internal:9944", "DB_TYPE=sqlite", @@ -17,7 +25,7 @@ pub async fn explorer() { "DISABLE_TESTNET_SYNC=true", "TESTNET_RPC_API_HOST=http://host.docker.internal:9944", "DATABASE_PATH=/use/exp.db", - "PHX_HOST=localhost", + host_env.as_str(), &secret_key_base, ]; diff --git a/src/main.rs b/src/main.rs index 001f17e..0412702 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use clap::{Parser, Subcommand}; use log::LevelFilter; use madara_cli::cli; +use madara_cli::cli::explorer::ExplorerOpts; #[derive(Parser)] #[command(author, version, about, long_about = None)] @@ -18,7 +19,7 @@ enum Commands { /// Runs the App Chain using Madara Run, /// Runs the L2 explorer - Explorer, + Explorer(ExplorerOpts), } #[tokio::main] @@ -36,7 +37,7 @@ async fn main() { Some(Commands::Init) => cli::init::init().await, Some(Commands::List) => cli::list::list(), Some(Commands::Run) => cli::run::run().await, - Some(Commands::Explorer) => cli::explorer::explorer().await, + Some(Commands::Explorer(opts)) => cli::explorer::explorer(opts).await, None => log::info!("Use --help to see the complete list of available commands"), } }