Skip to content

Commit 4932c1c

Browse files
benwilberabonander
authored andcommitted
feat(sqlx-cli): Add flag to disable automatic loading of .env files (launchbadge#3724)
* Add flag to disable automatic loading of .env files * Update sqlx-cli/src/opt.rs Co-authored-by: Austin Bonander <[email protected]> --------- Co-authored-by: Austin Bonander <[email protected]>
1 parent db649f9 commit 4932c1c

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

sqlx-cli/src/bin/cargo-sqlx.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ enum Cli {
1313

1414
#[tokio::main]
1515
async fn main() {
16-
dotenvy::dotenv().ok();
1716
let Cli::Sqlx(opt) = Cli::parse();
1817

18+
if !opt.no_dotenv {
19+
dotenvy::dotenv().ok();
20+
}
21+
1922
if let Err(error) = sqlx_cli::run(opt).await {
2023
println!("{} {}", style("error:").bold().red(), error);
2124
process::exit(1);

sqlx-cli/src/bin/sqlx.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ use sqlx_cli::Opt;
44

55
#[tokio::main]
66
async fn main() {
7-
dotenvy::dotenv().ok();
7+
let opt = Opt::parse();
8+
9+
if !opt.no_dotenv {
10+
dotenvy::dotenv().ok();
11+
}
12+
813
// no special handling here
9-
if let Err(error) = sqlx_cli::run(Opt::parse()).await {
14+
if let Err(error) = sqlx_cli::run(opt).await {
1015
println!("{} {}", style("error:").bold().red(), error);
1116
std::process::exit(1);
1217
}

sqlx-cli/src/opt.rs

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ use clap_complete::Shell;
77
#[derive(Parser, Debug)]
88
#[clap(version, about, author)]
99
pub struct Opt {
10+
/// Do not automatically load `.env` files.
11+
#[clap(long)]
12+
pub no_dotenv: bool,
13+
1014
#[clap(subcommand)]
1115
pub command: Command,
1216
}

0 commit comments

Comments
 (0)