@@ -8,7 +8,7 @@ use std::path::{Path, PathBuf};
8
8
use anstream:: eprint;
9
9
use anyhow:: { anyhow, bail, Context } ;
10
10
use futures:: StreamExt ;
11
- use itertools:: Itertools ;
11
+ use itertools:: { Either , Itertools } ;
12
12
use owo_colors:: OwoColorize ;
13
13
use tokio:: process:: Command ;
14
14
use tracing:: { debug, warn} ;
@@ -79,7 +79,7 @@ pub(crate) async fn run(
79
79
native_tls : bool ,
80
80
cache : & Cache ,
81
81
printer : Printer ,
82
- env_file : Option < PathBuf > ,
82
+ env_file : Vec < PathBuf > ,
83
83
no_env_file : bool ,
84
84
) -> anyhow:: Result < ExitStatus > {
85
85
// These cases seem quite complex because (in theory) they should change the "current package".
@@ -109,52 +109,58 @@ pub(crate) async fn run(
109
109
110
110
// Read from the `.env` file, if necessary.
111
111
if !no_env_file {
112
- let env_file_path = env_file. as_deref ( ) . unwrap_or_else ( || Path :: new ( ".env" ) ) ;
113
- match dotenvy:: from_path ( env_file_path) {
114
- Err ( dotenvy:: Error :: Io ( err) ) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => {
115
- if env_file. is_none ( ) {
116
- debug ! (
117
- "No environment file found at: `{}`" ,
118
- env_file_path. simplified_display( )
112
+ let env_file_paths = if env_file. is_empty ( ) {
113
+ Either :: Left ( std:: iter:: once ( Path :: new ( ".env" ) ) )
114
+ } else {
115
+ Either :: Right ( env_file. iter ( ) . rev ( ) . map ( PathBuf :: as_path) )
116
+ } ;
117
+ for env_file_path in env_file_paths {
118
+ match dotenvy:: from_path ( env_file_path) {
119
+ Err ( dotenvy:: Error :: Io ( err) ) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => {
120
+ if env_file. is_empty ( ) {
121
+ debug ! (
122
+ "No environment file found at: `{}`" ,
123
+ env_file_path. simplified_display( )
124
+ ) ;
125
+ } else {
126
+ bail ! (
127
+ "No environment file found at: `{}`" ,
128
+ env_file_path. simplified_display( )
129
+ ) ;
130
+ }
131
+ }
132
+ Err ( dotenvy:: Error :: Io ( err) ) => {
133
+ if env_file. is_empty ( ) {
134
+ debug ! (
135
+ "Failed to read environment file `{}`: {err}" ,
136
+ env_file_path. simplified_display( )
137
+ ) ;
138
+ } else {
139
+ bail ! (
140
+ "Failed to read environment file `{}`: {err}" ,
141
+ env_file_path. simplified_display( )
142
+ ) ;
143
+ }
144
+ }
145
+ Err ( dotenvy:: Error :: LineParse ( content, position) ) => {
146
+ warn_user ! (
147
+ "Failed to parse environment file `{}` at position {position}: {content}" ,
148
+ env_file_path. simplified_display( ) ,
119
149
) ;
120
- } else {
121
- bail ! (
122
- "No environment file found at: `{}`" ,
123
- env_file_path. simplified_display( )
150
+ }
151
+ Err ( err) => {
152
+ warn_user ! (
153
+ "Failed to parse environment file `{}`: {err}" ,
154
+ env_file_path. simplified_display( ) ,
124
155
) ;
125
156
}
126
- }
127
- Err ( dotenvy:: Error :: Io ( err) ) => {
128
- if env_file. is_none ( ) {
157
+ Ok ( ( ) ) => {
129
158
debug ! (
130
- "Failed to read environment file `{}`: {err}" ,
131
- env_file_path. simplified_display( )
132
- ) ;
133
- } else {
134
- bail ! (
135
- "Failed to read environment file `{}`: {err}" ,
159
+ "Read environment file at: `{}`" ,
136
160
env_file_path. simplified_display( )
137
161
) ;
138
162
}
139
163
}
140
- Err ( dotenvy:: Error :: LineParse ( content, position) ) => {
141
- warn_user ! (
142
- "Failed to parse environment file `{}` at position {position}: {content}" ,
143
- env_file_path. simplified_display( ) ,
144
- ) ;
145
- }
146
- Err ( err) => {
147
- warn_user ! (
148
- "Failed to parse environment file `{}`: {err}" ,
149
- env_file_path. simplified_display( ) ,
150
- ) ;
151
- }
152
- Ok ( ( ) ) => {
153
- debug ! (
154
- "Read environment file at: `{}`" ,
155
- env_file_path. simplified_display( )
156
- ) ;
157
- }
158
164
}
159
165
}
160
166
0 commit comments