Why: dotenv() must execute before clap's get_matches()

Co-authored-by: David James <davidcjames@gmail.com>
This commit is contained in:
David James
2021-09-10 18:06:49 -04:00
committed by GitHub
parent efd08cc4b3
commit bb33a296cb
3 changed files with 4 additions and 3 deletions

View File

@@ -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};
@@ -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")

View File

@@ -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

View File

@@ -1,5 +1,4 @@
use anyhow::Result;
use dotenv::dotenv;
use crate::opt::{Command, DatabaseCommand, MigrateCommand};
@@ -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 {