From 4da6d64988b0f379937ba26b33f7397f2d28729e Mon Sep 17 00:00:00 2001 From: vato007 Date: Wed, 17 Dec 2025 17:09:05 +1030 Subject: [PATCH] Make cli async so running the graph works, add schema generation to readme --- README.md | 6 ++++++ src/bin/{cli => ingey}/main.rs | 5 +++-- src/cli/mod.rs | 22 ++++++++++++---------- 3 files changed, 21 insertions(+), 12 deletions(-) rename src/bin/{cli => ingey}/main.rs (56%) diff --git a/README.md b/README.md index cafa368..ba88a60 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,12 @@ A super fast, simple base for building analytics applications. A basic CLI is available to run a graph and a subset of analytics workloads. In development environments, use `cargo run --bin cli -- -h` for more information. +### Generating the JSON schema: + +`cargo run --bin cli -- generate-schema` + +The schema will be written to a schema.json file. + ## General Notes Setting the number of threads in overhead allocation: set RAYON_NUM_THREADS environment diff --git a/src/bin/cli/main.rs b/src/bin/ingey/main.rs similarity index 56% rename from src/bin/cli/main.rs rename to src/bin/ingey/main.rs index 9c97ab7..b4c7dff 100644 --- a/src/bin/cli/main.rs +++ b/src/bin/ingey/main.rs @@ -1,8 +1,9 @@ use clap::Parser; use coster_rs::cli::Cli; -fn main() -> anyhow::Result<()> { +#[tokio::main] +async fn main() -> anyhow::Result<()> { env_logger::init(); let cli = Cli::parse(); - cli.run() + cli.run().await } diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 352dc92..c0ac61c 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -7,7 +7,7 @@ use std::{ use std::io::Write; -use clap::{command, Parser}; +use clap::Parser; pub use commands::Commands; @@ -23,17 +23,17 @@ use crate::{ mod commands; #[derive(Parser)] -#[command(name = "coster-rs")] -#[command(author = "Pivato M. ")] +#[command(name = "ingey")] +#[command(author = "Pivato M. ")] #[command(version = "0.0.1")] -#[command(about = "Simple, fast, efficient costing tool", long_about = None)] +#[command(about = "Simple, fast, efficient data manipulation tool", long_about = None)] pub struct Cli { #[clap(subcommand)] pub command: Commands, } impl Cli { - pub fn run(self) -> anyhow::Result<()> { + pub async fn run(self) -> anyhow::Result<()> { match self.command { Commands::MoveMoney { rules, @@ -174,11 +174,13 @@ impl Cli { let reader = BufReader::new(file); let graph = serde_json::from_reader(reader)?; let graph = RunnableGraph::from_graph(graph); - // TODO: Possible to await here? Actually needs awaiting to work - graph.run_default_tasks(threads, |id, status| { - info!("Node with id {} finished with status {:?}", id, status) - }); - Ok(()) + + let result = graph + .run_default_tasks(threads, |id, status| { + info!("Node with id {} finished with status {:?}", id, status) + }) + .await; + result } Commands::GenerateSchema { output } => { let schema = schema_for!(Graph);