diff --git a/Cargo.lock b/Cargo.lock index c07a009fa9..232195d103 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15320,6 +15320,7 @@ dependencies = [ "camino", "chrono", "clap", + "clap_complete", "clap_config", "ctrlc", "dojo-metrics", diff --git a/bin/torii/Cargo.toml b/bin/torii/Cargo.toml index 2e652a89ca..efa4339e0a 100644 --- a/bin/torii/Cargo.toml +++ b/bin/torii/Cargo.toml @@ -12,6 +12,7 @@ base64.workspace = true camino.workspace = true chrono.workspace = true clap.workspace = true +clap_complete.workspace = true ctrlc = { version = "3.4", features = [ "termination" ] } dojo-metrics.workspace = true dojo-types.workspace = true diff --git a/bin/torii/src/cli.rs b/bin/torii/src/cli.rs new file mode 100644 index 0000000000..1ebc62d347 --- /dev/null +++ b/bin/torii/src/cli.rs @@ -0,0 +1,14 @@ +//! CLI for Torii. +//! +//! Use a `Cli` struct to parse the CLI arguments +//! and to have flexibility in the future to add more commands +//! that may not start Torii directly. +use clap::Parser; +use torii_cli::ToriiArgs; + +#[derive(Parser)] +#[command(name = "torii", author, version, about, long_about = None)] +pub struct Cli { + #[command(flatten)] + pub args: ToriiArgs, +} diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index ff15a88644..29e222e26e 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -18,6 +18,7 @@ use std::time::Duration; use camino::Utf8PathBuf; use clap::Parser; +use cli::Cli; use dojo_metrics::exporters::prometheus::PrometheusRecorder; use dojo_world::contracts::world::WorldContractReader; use sqlx::sqlite::{ @@ -30,7 +31,6 @@ use tempfile::{NamedTempFile, TempDir}; use tokio::sync::broadcast; use tokio::sync::broadcast::Sender; use tokio_stream::StreamExt; -use torii_cli::ToriiArgs; use torii_core::engine::{Engine, EngineConfig, IndexingFlags, Processors}; use torii_core::executor::Executor; use torii_core::processors::store_transaction::StoreTransactionProcessor; @@ -46,9 +46,11 @@ use url::{form_urlencoded, Url}; pub(crate) const LOG_TARGET: &str = "torii::cli"; +mod cli; + #[tokio::main] async fn main() -> anyhow::Result<()> { - let mut args = ToriiArgs::parse().with_config_file()?; + let mut args = Cli::parse().args.with_config_file()?; let world_address = if let Some(world_address) = args.world_address { world_address @@ -56,7 +58,6 @@ async fn main() -> anyhow::Result<()> { return Err(anyhow::anyhow!("Please specify a world address.")); }; - // let mut contracts = parse_erc_contracts(&args.contracts)?; args.indexing.contracts.push(Contract { address: world_address, r#type: ContractType::WORLD }); let filter_layer = EnvFilter::try_from_default_env()