diff --git a/Cargo.lock b/Cargo.lock index 618afd45..98d25daa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,6 +42,12 @@ dependencies = [ "yansi", ] +[[package]] +name = "arraydeque" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" + [[package]] name = "autocfg" version = "1.5.0" @@ -69,6 +75,7 @@ version = "0.0.0" dependencies = [ "facet", "facet-toml", + "facet-yaml", "figue", ] @@ -415,6 +422,19 @@ dependencies = [ "indexmap", ] +[[package]] +name = "facet-yaml" +version = "0.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2455e0483ffec0c8cd6be75bdfa54cc0697add473445389eb5ecb5d887a7857d" +dependencies = [ + "facet", + "facet-core", + "facet-format", + "facet-reflect", + "saphyr-parser", +] + [[package]] name = "fastrand" version = "2.3.0" @@ -524,6 +544,15 @@ dependencies = [ "foldhash 0.2.0", ] +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.5", +] + [[package]] name = "heck" version = "0.5.0" @@ -811,6 +840,16 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "saphyr-parser" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb771b59f6b1985d1406325ec28f97cfb14256abcec4fdfb37b36a1766d6af7" +dependencies = [ + "arraydeque", + "hashlink", +] + [[package]] name = "semver" version = "1.0.27" diff --git a/bough.config.toml b/bough.config.toml deleted file mode 100644 index 75c34c26..00000000 --- a/bough.config.toml +++ /dev/null @@ -1,21 +0,0 @@ -bough_dir = "./.bough" -pwd = "examples/vitest-js" -ordering = "random" - -[init] -command = "npm install" - -[test] -command = "npm test" - -[test_ids] -get_all = "npm run --silent get-test-ids" -get_failed = "npm run --silent get-failed-test-ids" - -[mutate.js] -files.include = ["src/*.js"] -files.exclude = ["**/*.test.*"] -files.ignore_files = [] -mutants.skip = [ - { query = "(if_statement condition: (parenthesized_expression (member_expression object: (meta_property)))) @skip" }, -] diff --git a/crates/bough-cli/Cargo.toml b/crates/bough-cli/Cargo.toml index e970fc75..50e6cf9b 100644 --- a/crates/bough-cli/Cargo.toml +++ b/crates/bough-cli/Cargo.toml @@ -7,4 +7,5 @@ license.workspace = true [dependencies] facet = "0.44" facet-toml = "0.44" +facet-yaml = "0.44" figue = "2" diff --git a/crates/bough-cli/src/main.rs b/crates/bough-cli/src/main.rs index 69cf8d73..48d3674d 100644 --- a/crates/bough-cli/src/main.rs +++ b/crates/bough-cli/src/main.rs @@ -1,3 +1,5 @@ +use std::env; + use facet::Facet; use figue::{self as args, ConfigFormat, ConfigFormatError, Driver, builder}; @@ -49,25 +51,104 @@ impl ConfigFormat for TomlFormat { } } +struct YamlFormat; + +impl ConfigFormat for YamlFormat { + fn extensions(&self) -> &[&str] { + &["yaml", "yml"] + } + + fn parse(&self, contents: &str) -> Result { + facet_yaml::from_str(contents).map_err(|e| ConfigFormatError::new(e.to_string())) + } +} + +const CONFIG_NAMES: &[&str] = &[ + "bough.config.toml", + "bough.config.yaml", + "bough.config.yml", + "bough.config.json", + ".bough.toml", + ".bough.yaml", + ".bough.yml", + ".bough.json", + ".config/bough.toml", + ".config/bough.yaml", + ".config/bough.yml", + ".config/bough.json", +]; + +fn find_config_paths() -> Vec { + let mut paths = Vec::new(); + let mut dir = env::current_dir().ok(); + while let Some(d) = dir { + for name in CONFIG_NAMES { + paths.push(d.join(name).to_string_lossy().into_owned()); + } + dir = d.parent().map(|p| p.to_path_buf()); + } + paths +} + +fn resolve_config_path() -> Option { + find_config_paths() + .into_iter() + .find(|p| std::path::Path::new(p).is_file()) +} + fn main() { let config = builder::() .expect("schema should be valid") .cli(|cli| cli) .env(|env| env) - .file(|f| f.default_paths(["config.toml"]).format(TomlFormat)) + .file(|f| { + f.default_paths(find_config_paths()) + .format(TomlFormat) + .format(YamlFormat) + }) .build(); - let cli: Cli = Driver::new(config).run().unwrap(); + let outcome = Driver::new(config).run(); + let output = match outcome.into_result() { + Ok(output) => output, + Err(figue::DriverError::Help { text }) => { + println!("{text}"); + std::process::exit(0); + } + Err(figue::DriverError::Failed { report }) => { + eprintln!("{}", report.render_pretty()); + std::process::exit(1); + } + Err(e) => { + eprintln!("{e:?}"); + std::process::exit(1); + } + }; + output.print_warnings(); + + let config_path = resolve_config_path(); + let (cli, _report) = output.into_parts(); match cli.command { Command::Show { ref what } => match what { - ShowCommand::Cli => println!("{cli:#?}"), + ShowCommand::Cli => { + if let Some(ref path) = config_path { + println!("config file: {path}"); + } + println!("{cli:#?}"); + } ShowCommand::Config => { + if let Some(ref path) = config_path { + println!("config file: {path}"); + } println!("workers: {}", cli.config.workers); println!("id: {}", cli.config.id); } ShowCommand::File => { - println!("show file: not yet implemented"); + match config_path { + Some(ref path) => println!("{path}"), + None => println!("no config file found"), + } } }, Command::Run => {