diff --git a/Cargo.lock b/Cargo.lock index c0828e1..75032a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,6 +49,56 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + [[package]] name = "arbitrary" version = "1.4.2" @@ -410,6 +460,46 @@ dependencies = [ "windows-link", ] +[[package]] +name = "clap" +version = "4.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91e0c145792ef73a6ad36d27c75ac09f1832222a3c209689d90f534685ee5b7" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f09628afdcc538b57f3c6341e9c8e9970f18e4a481690a64974d7023bd33548b" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d012d2b9d65aca7f18f4d9878a045bc17899bba951561ba5ec3c2ba1eed9a061" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "clap_lex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" + [[package]] name = "cmake" version = "0.1.58" @@ -446,6 +536,12 @@ dependencies = [ "tracing-error", ] +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + [[package]] name = "combine" version = "4.6.7" @@ -1108,6 +1204,12 @@ version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + [[package]] name = "itoa" version = "1.0.18" @@ -1406,6 +1508,12 @@ version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + [[package]] name = "openssl-probe" version = "0.2.1" @@ -2021,6 +2129,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "strum" version = "0.27.2" @@ -2361,6 +2475,7 @@ version = "0.1.0" dependencies = [ "axum", "chrono", + "clap", "color-eyre", "duckdb", "r2d2", @@ -2422,6 +2537,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "valuable" version = "0.1.1" diff --git a/README.md b/README.md index 50e2816..4357e0a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Something I threw together to show the `sh.tangled.repo` activity. Might expand You'll need pnpm 11 and Node 26, then you should just be able to run `pnpm install` and `pnpm dev`. [This won't work on Safari](https://caniuse.com/temporal). -Oh, and you'll need rust btw to run `cargo run -p uplc` in another terminal. You should run this from the `uplc` directory for now. You'll need `libduckdb`, but if you don't have that or find it easier you can run with `--features 'duckdb/bundled'` and it _should_ sort it our for you. +Oh, and you'll need rust btw to run `cargo run -p uplc` in another terminal. You should run this from the `uplc` directory for now. You'll need `libduckdb`, but if you don't have that or find it easier you can run with `--features 'duckdb/bundled'` and it _should_ sort it our for you. You can run with `-- --no-sync` to not sync with the plc directory, which is useful after you let it run for a bit to stop it running forever in development. ### Thanks To diff --git a/uplc/Cargo.toml b/uplc/Cargo.toml index 86383c9..234b381 100644 --- a/uplc/Cargo.toml +++ b/uplc/Cargo.toml @@ -13,3 +13,4 @@ tokio = { version = "1.53.1", features = ["full"] } axum = "0.8.1" r2d2 = "0.8.10" chrono = "0.4.45" +clap = { version = "4.6.4", features = ["derive"] } diff --git a/uplc/src/main.rs b/uplc/src/main.rs index 2dfe36c..a9ed093 100644 --- a/uplc/src/main.rs +++ b/uplc/src/main.rs @@ -1,6 +1,7 @@ use std::sync::Arc; use crate::{api::run_api, db::DB, plc::run_plc_sync, stats::Stats}; +use clap::Parser; use color_eyre::eyre::Result; use tokio::sync::RwLock; @@ -9,22 +10,30 @@ mod db; mod plc; mod stats; +#[derive(Parser)] +struct Args { + #[clap( + default_value = "false", + long = "no-sync", + help = "Disable syncing with the plc" + )] + no_sync: bool, +} + #[tokio::main] async fn main() -> Result<()> { color_eyre::install()?; + let args = Args::parse(); let db = DB::new("./.data/uplc.db".into())?; println!("Loading initial stats..."); - let mut stats = Stats::default(); - stats.refresh(&db)?; - let stats = Arc::new(RwLock::new(stats)); - println!("Done! Starting sync & api"); + let stats = Arc::new(RwLock::new(Stats::default())); + stats.write().await.refresh(&db)?; - let plc_sync_handle = tokio::spawn({ - let db = db.clone(); - let stats = stats.clone(); - async move { run_plc_sync(db, stats).await } - }); + println!( + "Done! Starting api {}", + if args.no_sync { "(no sync)" } else { "& sync" } + ); let api_handle = tokio::spawn({ let db = db.clone(); @@ -32,9 +41,19 @@ async fn main() -> Result<()> { async move { run_api(db, stats).await } }); - tokio::select! { - result = api_handle => result??, - result = plc_sync_handle => result??, + if args.no_sync { + api_handle.await??; + } else { + let plc_sync_handle = tokio::spawn({ + let db = db.clone(); + let stats = stats.clone(); + async move { run_plc_sync(db, stats).await } + }); + + tokio::select! { + result = api_handle => result??, + result = plc_sync_handle => result??, + } } Ok(())