Skip to content

Commit

Permalink
Add flag to disable automatic loading of .env files
Browse files Browse the repository at this point in the history
  • Loading branch information
benwilber committed Feb 3, 2025
1 parent 65229f7 commit 1b11165
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion sqlx-cli/src/bin/cargo-sqlx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ enum Cli {

#[tokio::main]
async fn main() {
dotenvy::dotenv().ok();
let Cli::Sqlx(opt) = Cli::parse();

if !opt.no_dotenv {
dotenvy::dotenv().ok();
}

if let Err(error) = sqlx_cli::run(opt).await {
println!("{} {}", style("error:").bold().red(), error);
process::exit(1);
Expand Down
9 changes: 7 additions & 2 deletions sqlx-cli/src/bin/sqlx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ use sqlx_cli::Opt;

#[tokio::main]
async fn main() {
dotenvy::dotenv().ok();
let opt = Opt::parse();

if !opt.no_dotenv {
dotenvy::dotenv().ok();
}

// no special handling here
if let Err(error) = sqlx_cli::run(Opt::parse()).await {
if let Err(error) = sqlx_cli::run(opt).await {
println!("{} {}", style("error:").bold().red(), error);
std::process::exit(1);
}
Expand Down
4 changes: 4 additions & 0 deletions sqlx-cli/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use clap_complete::Shell;
#[derive(Parser, Debug)]
#[clap(version, about, author)]
pub struct Opt {
/// Do not automatically load `.env` files.
#[clap(long, default_value = "false")]
pub no_dotenv: bool,

#[clap(subcommand)]
pub command: Command,
}
Expand Down

0 comments on commit 1b11165

Please sign in to comment.