From 48a55a407b26a3040369ad0fdcc51aeafa677aa0 Mon Sep 17 00:00:00 2001 From: LMJW Date: Sun, 16 Aug 2020 16:27:32 +1000 Subject: [PATCH] fix(issue #558) - check the existance of `Cargo.toml` at current working directory before checking 'DATABASE_URL' environment variable --- sqlx-cli/src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sqlx-cli/src/lib.rs b/sqlx-cli/src/lib.rs index b38261c64..1f1ca0598 100644 --- a/sqlx-cli/src/lib.rs +++ b/sqlx-cli/src/lib.rs @@ -1,7 +1,8 @@ use crate::opt::{Command, DatabaseCommand, MigrateCommand}; -use anyhow::anyhow; +use anyhow::{anyhow, bail}; use dotenv::dotenv; use std::env; +use std::path::Path; mod database; // mod migration; @@ -13,6 +14,13 @@ mod prepare; pub use crate::opt::Opt; pub async fn run(opt: Opt) -> anyhow::Result<()> { + if !Path::new("Cargo.toml").exists() { + bail!( + r#"Failed to read `Cargo.toml`. +hint: This command only works in the manifest directory of a Cargo package."# + ); + } + dotenv().ok(); let database_url = match opt.database_url {