From 8a8881c29c9dca92beb25e30f0bdcbd223a4a681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Mon, 17 Feb 2025 11:45:13 +0100 Subject: [PATCH 1/3] project info schema-dir --- src/portable/project/info.rs | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/portable/project/info.rs b/src/portable/project/info.rs index 1f42dc32..b5b3cf2e 100644 --- a/src/portable/project/info.rs +++ b/src/portable/project/info.rs @@ -5,18 +5,18 @@ use clap::ValueHint; use const_format::concatcp; use gel_tokio::get_stash_path; +use crate::branding::BRANDING_CLI_CMD; use crate::branding::BRANDING_CLOUD; -use crate::branding::{BRANDING_CLI_CMD, MANIFEST_FILE_DISPLAY_NAME}; use crate::commands::ExitCode; use crate::portable::project; use crate::print::{self, msg, Highlight}; use crate::table; pub fn run(options: &Command) -> anyhow::Result<()> { - let Some(project) = project::find_project(options.project_dir.as_deref())? else { - anyhow::bail!("`{MANIFEST_FILE_DISPLAY_NAME}` not found, unable to get project info."); - }; - let stash_dir = get_stash_path(&project.root)?; + let ctx = project::ensure_ctx(options.project_dir.as_deref())?; + let schema_dir = ctx.resolve_schema_dir()?; + + let stash_dir = get_stash_path(&ctx.location.root)?; if !stash_dir.exists() { msg!( "{} {} Run `{BRANDING_CLI_CMD} project init`.", @@ -52,6 +52,13 @@ pub fn run(options: &Command) -> anyhow::Result<()> { println!("{profile}"); } } + "schema-dir" => { + if options.json { + println!("{}", serde_json::to_string(&schema_dir)?); + } else { + println!("{}", schema_dir.display()); + } + } _ => unreachable!(), } } else if options.json { @@ -60,13 +67,19 @@ pub fn run(options: &Command) -> anyhow::Result<()> { serde_json::to_string_pretty(&JsonInfo { instance_name: &instance_name, cloud_profile: cloud_profile.as_deref(), - root: &project.root, + root: &ctx.location.root, + schema_dir: &schema_dir, })? ); } else { - let root = project.root.display().to_string(); - let mut rows: Vec<(&str, String)> = - vec![("Instance name", instance_name), ("Project root", root)]; + let root = ctx.location.root.display().to_string(); + let schema_dir = schema_dir.display().to_string(); + + let mut rows: Vec<(&str, String)> = vec![ + ("Instance name", instance_name), + ("Project root", root), + ("Schema dir", schema_dir), + ]; if let Some(profile) = cloud_profile.as_deref() { rows.push((concatcp!(BRANDING_CLOUD, " profile"), profile.to_string())); } @@ -92,6 +105,7 @@ pub struct Command { #[arg(long, value_parser=[ "instance-name", "cloud-profile", + "schema-dir", ])] /// Get a specific value: /// @@ -106,4 +120,5 @@ struct JsonInfo<'a> { #[serde(skip_serializing_if = "Option::is_none")] cloud_profile: Option<&'a str>, root: &'a Path, + schema_dir: &'a Path, } From 9fdf8e25ad3775d15ce329170d6e692c5eb23213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Mon, 17 Feb 2025 11:50:45 +0100 Subject: [PATCH 2/3] add tests for projects with both gel.toml and edgedb.toml --- tests/portable_project.rs | 74 ++++++++++++++++++++++++++++++++++ tests/proj/project4/.gitignore | 2 + tests/proj/project4/gel.toml | 5 +++ 3 files changed, 81 insertions(+) create mode 100644 tests/proj/project4/.gitignore create mode 100644 tests/proj/project4/gel.toml diff --git a/tests/portable_project.rs b/tests/portable_project.rs index 816cbdb2..7ec35cd5 100644 --- a/tests/portable_project.rs +++ b/tests/portable_project.rs @@ -376,3 +376,77 @@ impl<'a> std::fmt::Display for ContainsHooks<'a> { std::fmt::Debug::fmt(&self, f) } } + +#[test] +fn backward_compat() { + use std::{fs, path}; + + Command::new("edgedb") + .arg("--version") + .assert() + .context("version", "command-line version option") + .success() + .stdout(predicates::str::contains(EXPECTED_VERSION)); + + Command::new("edgedb") + .arg("instance") + .arg("create") + .arg("inst3") + .assert() + .context("create-3", "created `inst3`") + .success(); + + let gel_toml = path::Path::new("tests/proj/project4/gel.toml"); + let edgedb_toml = path::Path::new("tests/proj/project4/edgedb.toml"); + fs::remove_file(edgedb_toml).ok(); + + Command::new("edgedb") + .arg("project") + .arg("init") + .arg("--link") + .arg("--server-instance=inst3") + .arg("--non-interactive") + .current_dir("tests/proj/project4") + .assert() + .context("project-link", "linked `inst3` to project project4"); + + // just gel.toml + Command::new("edgedb") + .arg("project") + .arg("info") + .arg("--get=schema-dir") + .current_dir("tests/proj/project4") + .assert() + .context("project-info-just-gel", "") + .stdout(predicates::str::contains("/database_schema")) + .success(); + + // both gel.toml and edgedb.toml, identical + fs::copy(gel_toml, edgedb_toml).ok(); + Command::new("edgedb") + .arg("project") + .arg("info") + .current_dir("tests/proj/project4") + .assert() + .context("project-info-identical", "") + .stdout(predicates::str::contains("/database_schema")) + .success(); + + // both gel.toml and edgedb.toml, different + fs::write( + edgedb_toml, + r#" +[edgedb] +server-version = "1.0" +"#, + ) + .ok(); + Command::new("edgedb") + .arg("project") + .arg("info") + .current_dir("tests/proj/project4") + .assert() + .context("project-info-different", "") + .stderr(predicates::str::contains("but the contents are different")) + .failure(); +} diff --git a/tests/proj/project4/.gitignore b/tests/proj/project4/.gitignore new file mode 100644 index 00000000..5e9dbada --- /dev/null +++ b/tests/proj/project4/.gitignore @@ -0,0 +1,2 @@ +./dbschema +edgedb.toml \ No newline at end of file diff --git a/tests/proj/project4/gel.toml b/tests/proj/project4/gel.toml new file mode 100644 index 00000000..2a738c02 --- /dev/null +++ b/tests/proj/project4/gel.toml @@ -0,0 +1,5 @@ +[instance] +server-version = "nightly" + +[project] +schema-dir = "./database_schema" \ No newline at end of file From f8433bc6ae088b655b51f5c44e53453433be2297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Mon, 17 Feb 2025 11:54:01 +0100 Subject: [PATCH 3/3] Revert "add tests for projects with both gel.toml and edgedb.toml" This reverts commit 9fdf8e25ad3775d15ce329170d6e692c5eb23213. --- tests/portable_project.rs | 74 ---------------------------------- tests/proj/project4/.gitignore | 2 - tests/proj/project4/gel.toml | 5 --- 3 files changed, 81 deletions(-) delete mode 100644 tests/proj/project4/.gitignore delete mode 100644 tests/proj/project4/gel.toml diff --git a/tests/portable_project.rs b/tests/portable_project.rs index 7ec35cd5..816cbdb2 100644 --- a/tests/portable_project.rs +++ b/tests/portable_project.rs @@ -376,77 +376,3 @@ impl<'a> std::fmt::Display for ContainsHooks<'a> { std::fmt::Debug::fmt(&self, f) } } - -#[test] -fn backward_compat() { - use std::{fs, path}; - - Command::new("edgedb") - .arg("--version") - .assert() - .context("version", "command-line version option") - .success() - .stdout(predicates::str::contains(EXPECTED_VERSION)); - - Command::new("edgedb") - .arg("instance") - .arg("create") - .arg("inst3") - .assert() - .context("create-3", "created `inst3`") - .success(); - - let gel_toml = path::Path::new("tests/proj/project4/gel.toml"); - let edgedb_toml = path::Path::new("tests/proj/project4/edgedb.toml"); - fs::remove_file(edgedb_toml).ok(); - - Command::new("edgedb") - .arg("project") - .arg("init") - .arg("--link") - .arg("--server-instance=inst3") - .arg("--non-interactive") - .current_dir("tests/proj/project4") - .assert() - .context("project-link", "linked `inst3` to project project4"); - - // just gel.toml - Command::new("edgedb") - .arg("project") - .arg("info") - .arg("--get=schema-dir") - .current_dir("tests/proj/project4") - .assert() - .context("project-info-just-gel", "") - .stdout(predicates::str::contains("/database_schema")) - .success(); - - // both gel.toml and edgedb.toml, identical - fs::copy(gel_toml, edgedb_toml).ok(); - Command::new("edgedb") - .arg("project") - .arg("info") - .current_dir("tests/proj/project4") - .assert() - .context("project-info-identical", "") - .stdout(predicates::str::contains("/database_schema")) - .success(); - - // both gel.toml and edgedb.toml, different - fs::write( - edgedb_toml, - r#" -[edgedb] -server-version = "1.0" -"#, - ) - .ok(); - Command::new("edgedb") - .arg("project") - .arg("info") - .current_dir("tests/proj/project4") - .assert() - .context("project-info-different", "") - .stderr(predicates::str::contains("but the contents are different")) - .failure(); -} diff --git a/tests/proj/project4/.gitignore b/tests/proj/project4/.gitignore deleted file mode 100644 index 5e9dbada..00000000 --- a/tests/proj/project4/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -./dbschema -edgedb.toml \ No newline at end of file diff --git a/tests/proj/project4/gel.toml b/tests/proj/project4/gel.toml deleted file mode 100644 index 2a738c02..00000000 --- a/tests/proj/project4/gel.toml +++ /dev/null @@ -1,5 +0,0 @@ -[instance] -server-version = "nightly" - -[project] -schema-dir = "./database_schema" \ No newline at end of file