diff --git a/Cargo.lock b/Cargo.lock index 7d6e6304..6900a44a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -754,6 +754,16 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +[[package]] +name = "cargo_toml" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8cb1d556b8b8f36e5ca74938008be3ac102f5dcb5b68a0477e4249ae2291cd3" +dependencies = [ + "serde", + "toml", +] + [[package]] name = "cast" version = "0.3.0" @@ -2445,7 +2455,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" dependencies = [ - "toml_edit", + "toml_edit 0.21.1", ] [[package]] @@ -2561,6 +2571,7 @@ dependencies = [ "assert_cmd", "async-trait", "base64 0.22.0", + "cargo_toml", "chrono", "clap", "dbt-converter", @@ -3187,6 +3198,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -3967,11 +3987,26 @@ dependencies = [ "tracing", ] +[[package]] +name = "toml" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.22.12", +] + [[package]] name = "toml_datetime" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -3981,7 +4016,20 @@ checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ "indexmap", "toml_datetime", - "winnow", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.22.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow 0.6.7", ] [[package]] @@ -4487,6 +4535,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.50.0" diff --git a/rust/cli/Cargo.toml b/rust/cli/Cargo.toml index be5276ff..634a3092 100644 --- a/rust/cli/Cargo.toml +++ b/rust/cli/Cargo.toml @@ -21,6 +21,7 @@ futures = "0.3.30" base64 = "0.22.0" dotenv = "0.15" serde_yaml = "0.9.33" +cargo_toml = "0.20.2" [dev-dependencies] chrono = "0.4.38" diff --git a/rust/cli/src/commands.rs b/rust/cli/src/commands.rs index 68db1520..f18642fa 100644 --- a/rust/cli/src/commands.rs +++ b/rust/cli/src/commands.rs @@ -1,9 +1,10 @@ +use cargo_toml::{Dependency, Manifest}; use clap::{Args, Parser, Subcommand, ValueEnum}; use quary_proto::TestRunner; #[derive(Debug, Parser)] #[command(name = "quary")] -#[command(about = "A tool for managing SQL transformations and tests. For more documentation on these commands, visit: quary.dev/docs", long_about = None, version=env!("CARGO_PKG_VERSION"))] +#[command(about = "A tool for managing SQL transformations and tests. For more documentation on these commands, visit: quary.dev/docs", long_about = None, version = get_version())] pub struct Cli { #[command(subcommand)] pub command: Commands, @@ -141,3 +142,39 @@ pub fn mode_to_test_runner(mode: &TestMode) -> TestRunner { TestMode::Skip => TestRunner::Skip, } } + +fn get_version() -> String { + let manifest_path = std::env::var("CARGO_MANIFEST_DIR").unwrap() + "/Cargo.toml"; + let manifest = Manifest::from_path(&manifest_path).unwrap(); + + let duckdb_version = manifest + .dependencies + .get("duckdb") + .unwrap(); + + let duckdb_version = match duckdb_version { + Dependency::Simple(simple) => { + simple.to_string() + } + Dependency::Inherited(_) => { + unimplemented!() + } + Dependency::Detailed(_) => { + unimplemented!() + } + }; + + format!("quary version: {}\nDependiencies version\n\tduckdb: {}", env!("CARGO_PKG_VERSION"), duckdb_version) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_get_version() { + let version = get_version(); + assert!(version.contains("quary: ")); + assert!(version.contains("duckdb: ")); + } +}