@@ -8,7 +8,7 @@ use std::path::{Path, PathBuf};
88use anstream:: eprint;
99use anyhow:: { anyhow, bail, Context } ;
1010use futures:: StreamExt ;
11- use itertools:: Itertools ;
11+ use itertools:: { Either , Itertools } ;
1212use owo_colors:: OwoColorize ;
1313use tokio:: process:: Command ;
1414use tracing:: { debug, warn} ;
@@ -81,7 +81,7 @@ pub(crate) async fn run(
8181 native_tls : bool ,
8282 cache : & Cache ,
8383 printer : Printer ,
84- env_file : Option < PathBuf > ,
84+ env_file : Vec < PathBuf > ,
8585 no_env_file : bool ,
8686) -> anyhow:: Result < ExitStatus > {
8787 // These cases seem quite complex because (in theory) they should change the "current package".
@@ -111,52 +111,58 @@ pub(crate) async fn run(
111111
112112 // Read from the `.env` file, if necessary.
113113 if !no_env_file {
114- let env_file_path = env_file. as_deref ( ) . unwrap_or_else ( || Path :: new ( ".env" ) ) ;
115- match dotenvy:: from_path ( env_file_path) {
116- Err ( dotenvy:: Error :: Io ( err) ) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => {
117- if env_file. is_none ( ) {
118- debug ! (
119- "No environment file found at: `{}`" ,
120- env_file_path. simplified_display( )
114+ let env_file_paths = if env_file. is_empty ( ) {
115+ Either :: Left ( std:: iter:: once ( Path :: new ( ".env" ) ) )
116+ } else {
117+ Either :: Right ( env_file. iter ( ) . rev ( ) . map ( PathBuf :: as_path) )
118+ } ;
119+ for env_file_path in env_file_paths {
120+ match dotenvy:: from_path ( env_file_path) {
121+ Err ( dotenvy:: Error :: Io ( err) ) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => {
122+ if env_file. is_empty ( ) {
123+ debug ! (
124+ "No environment file found at: `{}`" ,
125+ env_file_path. simplified_display( )
126+ ) ;
127+ } else {
128+ bail ! (
129+ "No environment file found at: `{}`" ,
130+ env_file_path. simplified_display( )
131+ ) ;
132+ }
133+ }
134+ Err ( dotenvy:: Error :: Io ( err) ) => {
135+ if env_file. is_empty ( ) {
136+ debug ! (
137+ "Failed to read environment file `{}`: {err}" ,
138+ env_file_path. simplified_display( )
139+ ) ;
140+ } else {
141+ bail ! (
142+ "Failed to read environment file `{}`: {err}" ,
143+ env_file_path. simplified_display( )
144+ ) ;
145+ }
146+ }
147+ Err ( dotenvy:: Error :: LineParse ( content, position) ) => {
148+ warn_user ! (
149+ "Failed to parse environment file `{}` at position {position}: {content}" ,
150+ env_file_path. simplified_display( ) ,
121151 ) ;
122- } else {
123- bail ! (
124- "No environment file found at: `{}`" ,
125- env_file_path. simplified_display( )
152+ }
153+ Err ( err) => {
154+ warn_user ! (
155+ "Failed to parse environment file `{}`: {err}" ,
156+ env_file_path. simplified_display( ) ,
126157 ) ;
127158 }
128- }
129- Err ( dotenvy:: Error :: Io ( err) ) => {
130- if env_file. is_none ( ) {
159+ Ok ( ( ) ) => {
131160 debug ! (
132- "Failed to read environment file `{}`: {err}" ,
133- env_file_path. simplified_display( )
134- ) ;
135- } else {
136- bail ! (
137- "Failed to read environment file `{}`: {err}" ,
161+ "Read environment file at: `{}`" ,
138162 env_file_path. simplified_display( )
139163 ) ;
140164 }
141165 }
142- Err ( dotenvy:: Error :: LineParse ( content, position) ) => {
143- warn_user ! (
144- "Failed to parse environment file `{}` at position {position}: {content}" ,
145- env_file_path. simplified_display( ) ,
146- ) ;
147- }
148- Err ( err) => {
149- warn_user ! (
150- "Failed to parse environment file `{}`: {err}" ,
151- env_file_path. simplified_display( ) ,
152- ) ;
153- }
154- Ok ( ( ) ) => {
155- debug ! (
156- "Read environment file at: `{}`" ,
157- env_file_path. simplified_display( )
158- ) ;
159- }
160166 }
161167 }
162168
0 commit comments