Don't require Cargo.toml for all subcommands

This commit is contained in:
AriusX7 2021-01-26 19:00:29 +05:30 committed by Ryan Leckey
parent 1b217cfac4
commit 264cb09528
2 changed files with 8 additions and 10 deletions

View File

@ -1,8 +1,7 @@
use crate::opt::{Command, DatabaseCommand, MigrateCommand};
use anyhow::{anyhow, bail};
use anyhow::anyhow;
use dotenv::dotenv;
use std::env;
use std::path::Path;
mod database;
// mod migration;
@ -14,13 +13,6 @@ 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 {

View File

@ -6,7 +6,7 @@ use sqlx::any::{AnyConnectOptions, AnyKind};
use std::collections::BTreeMap;
use std::fs::File;
use std::io::{BufReader, BufWriter};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str::FromStr;
use std::time::SystemTime;
@ -23,6 +23,12 @@ pub fn run(url: &str, merge: bool, cargo_args: Vec<String>) -> anyhow::Result<()
data: QueryData,
}
anyhow::ensure!(
Path::new("Cargo.toml").exists(),
r#"Failed to read `Cargo.toml`.
hint: This command only works in the manifest directory of a Cargo package."#
);
let db_kind = get_db_kind(url)?;
let data = run_prepare_step(merge, cargo_args)?;