Skip to content

Commit

Permalink
Fix issue launchbadge#1431
Browse files Browse the repository at this point in the history
Why: dotenv() must execute before clap's get_matches()
  • Loading branch information
David James committed Sep 8, 2021
1 parent 2eb4ff8 commit 354a25f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 2 additions & 0 deletions sqlx-cli/src/bin/cargo-sqlx.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::{crate_version, AppSettings, FromArgMatches, IntoApp};
use console::style;
use dotenv::dotenv;
use sqlx_cli::Opt;
use std::{env, process};

Expand All @@ -9,6 +10,7 @@ async fn main() {
// so we want to notch out that superfluous "sqlx"
let args = env::args_os().skip(2);

dotenv().ok();
let matches = Opt::into_app()
.version(crate_version!())
.bin_name("cargo sqlx")
Expand Down
2 changes: 2 additions & 0 deletions sqlx-cli/src/bin/sqlx.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use clap::{crate_version, FromArgMatches, IntoApp};
use console::style;
use dotenv::dotenv;
use sqlx_cli::Opt;

#[tokio::main]
async fn main() {
dotenv().ok();
let matches = Opt::into_app().version(crate_version!()).get_matches();

// no special handling here
Expand Down
3 changes: 0 additions & 3 deletions sqlx-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::Result;
use dotenv::dotenv;

use crate::opt::{Command, DatabaseCommand, MigrateCommand};

Expand All @@ -13,8 +12,6 @@ mod prepare;
pub use crate::opt::Opt;

pub async fn run(opt: Opt) -> Result<()> {
dotenv().ok();

match opt.command {
Command::Migrate(migrate) => match migrate.command {
MigrateCommand::Add {
Expand Down

0 comments on commit 354a25f

Please sign in to comment.