-
Notifications
You must be signed in to change notification settings - Fork 194
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
feat(torii): configutation file for all torii cli options #2646
Changes from 1 commit
d6c77c0
3108039
aa985f7
7c19061
cf20035
f671543
8b41cf2
a2c064e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ use clap::{ArgAction, Parser}; | |
use dojo_metrics::exporters::prometheus::PrometheusRecorder; | ||
use dojo_utils::parse::{parse_socket_address, parse_url}; | ||
use dojo_world::contracts::world::WorldContractReader; | ||
use serde::{Deserialize, Serialize}; | ||
use sqlx::sqlite::{ | ||
SqliteAutoVacuum, SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous, | ||
}; | ||
|
@@ -39,7 +40,7 @@ use torii_core::executor::Executor; | |
use torii_core::processors::store_transaction::StoreTransactionProcessor; | ||
use torii_core::simple_broker::SimpleBroker; | ||
use torii_core::sql::Sql; | ||
use torii_core::types::{Contract, ContractType, Model, ToriiConfig}; | ||
use torii_core::types::{Contract, ContractType, Model}; | ||
use torii_server::proxy::Proxy; | ||
use tracing::{error, info}; | ||
use tracing_subscriber::{fmt, EnvFilter}; | ||
|
@@ -48,7 +49,7 @@ use url::{form_urlencoded, Url}; | |
pub(crate) const LOG_TARGET: &str = "torii::cli"; | ||
|
||
/// Dojo World Indexer | ||
#[derive(Parser, Debug)] | ||
#[derive(Parser, Debug, Serialize, Deserialize)] | ||
#[command(name = "torii", author, version, about, long_about = None)] | ||
struct Args { | ||
/// The world to index | ||
|
@@ -148,20 +149,24 @@ struct Args { | |
config: Option<PathBuf>, | ||
} | ||
|
||
impl Args { | ||
fn from_file(path: &PathBuf) -> anyhow::Result<Self> { | ||
let content = std::fs::read_to_string(path) | ||
.with_context(|| format!("Failed to read config file: {}", path.display()))?; | ||
|
||
toml::from_str(&content) | ||
.with_context(|| "Failed to parse TOML config") | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let args = Args::parse(); | ||
|
||
let mut config = if let Some(path) = args.config { | ||
ToriiConfig::load_from_path(&path)? | ||
let args = if let Some(path) = args.config { | ||
Args::from_file(&path)? | ||
} else { | ||
let mut config = ToriiConfig::default(); | ||
|
||
if let Some(contracts) = args.contracts { | ||
config.contracts = VecDeque::from(contracts); | ||
} | ||
|
||
config | ||
args | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Ohayo sensei! Your configuration concerns are valid and need attention! The codebase analysis reveals:
Action items:
🔗 Analysis chainOhayo sensei! Let's address some configuration concerns! The configuration loading logic could benefit from some improvements:
Let's check if there's any existing documentation about the config file format: Consider adding a README section or documentation file explaining:
Let me analyze the codebase more thoroughly to verify the concerns about configuration documentation and handling. The previous search was too narrow and didn't check the repository structure properly. I need to verify how the config file is handled and if there's any existing documentation in the torii-specific README before making a final determination about the configuration concerns. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Look for config file documentation
echo "Checking for config documentation..."
rg -i "config.*file.*format|toml.*config|configuration.*file" README.md docs/
Length of output: 208 Script: #!/bin/bash
# Let's check for any documentation about configuration in the repository
echo "Checking for any documentation files..."
fd -e md
# Look for TOML-related code and comments
echo -e "\nChecking for TOML-related code..."
rg -i "toml" --type rust
# Check the Args struct definition to understand config handling
echo -e "\nChecking Args struct definition..."
rg "struct Args" -A 20 bin/torii/src/
Length of output: 9376 Script: #!/bin/bash
# Let's check the implementation of Args::from_file to understand config handling
echo "Checking Args::from_file implementation..."
rg -A 10 "impl.*Args" bin/torii/src/
# Look for any existing config examples or tests
echo -e "\nChecking for config examples or tests..."
rg "config.*toml" bin/torii/
# Check the bin/torii README for any documentation
echo -e "\nChecking torii README..."
cat bin/torii/README.md
Length of output: 1063 |
||
}; | ||
|
||
let world_address = verify_single_world_address(args.world_address, &mut config)?; | ||
|
@@ -321,26 +326,6 @@ async fn main() -> anyhow::Result<()> { | |
Ok(()) | ||
} | ||
|
||
// Verifies that the world address is defined at most once | ||
// and returns the world address | ||
fn verify_single_world_address( | ||
world_address: Option<Felt>, | ||
config: &mut ToriiConfig, | ||
) -> anyhow::Result<Felt> { | ||
let world_from_config = | ||
config.contracts.iter().find(|c| c.r#type == ContractType::WORLD).map(|c| c.address); | ||
|
||
match (world_address, world_from_config) { | ||
(Some(_), Some(_)) => Err(anyhow::anyhow!("World address specified multiple times")), | ||
(Some(addr), _) => { | ||
config.contracts.push_front(Contract { address: addr, r#type: ContractType::WORLD }); | ||
Ok(addr) | ||
} | ||
(_, Some(addr)) => Ok(addr), | ||
(None, None) => Err(anyhow::anyhow!("World address not specified")), | ||
} | ||
} | ||
|
||
async fn spawn_rebuilding_graphql_server( | ||
shutdown_tx: Sender<()>, | ||
pool: Arc<SqlitePool>, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Ohayo sensei! Let's enhance the error handling and validation!
The
from_file
implementation could benefit from some improvements:Here's a suggested improvement:
📝 Committable suggestion