diff --git a/Cargo.lock b/Cargo.lock index c2b677a..6f2241b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,15 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "anstream" version = "0.6.18" @@ -517,6 +526,15 @@ version = "0.4.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "md-5" version = "0.10.6" @@ -773,6 +791,50 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.9", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -1086,10 +1148,14 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" dependencies = [ + "matchers", "nu-ansi-term", + "once_cell", + "regex", "sharded-slab", "smallvec", "thread_local", + "tracing", "tracing-core", "tracing-log", ] diff --git a/Cargo.toml b/Cargo.toml index 5579220..8929c8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ resolver = "2" anyhow = { version = "1" } tokio = { version = "1", features = ["full"] } tracing = { version = "0.1", features = ["log"] } -tracing-subscriber = { version = "0.3.18" } +tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } clap = { version = "4", features = ["derive", "env", "cargo", "string"] } dotenvy = { version = "0.15" } serde = { version = "1", features = ["derive"] } diff --git a/crates/forest/src/cli.rs b/crates/forest/src/cli.rs index b30321d..87139f0 100644 --- a/crates/forest/src/cli.rs +++ b/crates/forest/src/cli.rs @@ -19,6 +19,7 @@ enum Commands { Init {}, Template(template::Template), Info {}, + Clean {}, Serve { #[arg(env = "FOREST_HOST", long, default_value = "127.0.0.1:3000")] host: SocketAddr, @@ -54,9 +55,7 @@ fn get_root(include_run: bool) -> clap::Command { ); if include_run { - root_cmd = root_cmd - .subcommand(clap::Command::new("run").allow_external_subcommands(true)) - .ignore_errors(true); + root_cmd = root_cmd.subcommand(clap::Command::new("run").allow_external_subcommands(true)); } Commands::augment_subcommands(root_cmd) @@ -112,7 +111,10 @@ pub async fn execute() -> anyhow::Result<()> { matches }; - match matches.subcommand().unwrap() { + match matches + .subcommand() + .expect("forest requires a command to be passed") + { ("run", args) => { run::Run::execute(args, &project_path, &context).await?; } @@ -148,6 +150,13 @@ pub async fn execute() -> anyhow::Result<()> { let _url = put_object.sign(std::time::Duration::from_secs(30)); let _state = SharedState::new().await?; } + Commands::Clean {} => { + let forest_path = project_path.join(".forest"); + if forest_path.exists() { + tokio::fs::remove_dir_all(forest_path).await?; + tracing::info!("removed .forest"); + } + } }, } diff --git a/crates/forest/src/cli/run.rs b/crates/forest/src/cli/run.rs index 26a8da5..8df355e 100644 --- a/crates/forest/src/cli/run.rs +++ b/crates/forest/src/cli/run.rs @@ -71,6 +71,6 @@ impl Run { } } - Ok(()) + anyhow::bail!("no scripts were found for command: {}", name) } } diff --git a/crates/forest/src/main.rs b/crates/forest/src/main.rs index 57c0d77..5542e0a 100644 --- a/crates/forest/src/main.rs +++ b/crates/forest/src/main.rs @@ -1,3 +1,6 @@ +use tracing::level_filters::LevelFilter; +use tracing_subscriber::EnvFilter; + pub mod cli; pub mod model; pub mod plan_reconciler; @@ -7,7 +10,14 @@ pub mod state; #[tokio::main] async fn main() -> anyhow::Result<()> { dotenvy::dotenv().ok(); - tracing_subscriber::fmt::init(); + tracing_subscriber::fmt() + .with_env_filter( + EnvFilter::builder() + .with_default_directive(LevelFilter::WARN.into()) + .with_env_var("FOREST_LOG_LEVEL") + .from_env()?, + ) + .init(); cli::execute().await?; diff --git a/crates/forest/src/script.rs b/crates/forest/src/script.rs index 06f0038..f60c139 100644 --- a/crates/forest/src/script.rs +++ b/crates/forest/src/script.rs @@ -26,7 +26,7 @@ impl ScriptExecutor { return Ok(()); } - Ok(()) + anyhow::bail!("script was not found for name: {}", name) } async fn run_project(&self, script_ctx: &Script, name: &str) -> anyhow::Result {