@@ -58,9 +58,10 @@ pub async fn main() {
5858 )
5959 . arg (
6060 Arg :: with_name ( "file" )
61- . help ( "Execute commands from file, then exit" )
61+ . help ( "Execute commands from file(s) , then exit" )
6262 . short ( "f" )
6363 . long ( "file" )
64+ . multiple ( true )
6465 . validator ( is_valid_file)
6566 . takes_value ( true ) ,
6667 )
@@ -112,22 +113,25 @@ pub async fn main() {
112113 let quiet = matches. is_present ( "quiet" ) ;
113114 let print_options = PrintOptions { format, quiet } ;
114115
115- if let Some ( file_path) = matches. value_of ( "file" ) {
116- let file = File :: open ( file_path)
117- . unwrap_or_else ( |err| panic ! ( "cannot open file '{}': {}" , file_path, err) ) ;
118- let mut reader = BufReader :: new ( file) ;
119- exec_from_lines ( & mut reader, execution_config, print_options) . await ;
116+ if let Some ( file_paths) = matches. values_of ( "file" ) {
117+ let files = file_paths
118+ . map ( |file_path| File :: open ( file_path) . unwrap ( ) )
119+ . collect :: < Vec < _ > > ( ) ;
120+ let mut ctx = ExecutionContext :: with_config ( execution_config) ;
121+ for file in files {
122+ let mut reader = BufReader :: new ( file) ;
123+ exec_from_lines ( & mut ctx, & mut reader, print_options. clone ( ) ) . await ;
124+ }
120125 } else {
121126 exec_from_repl ( execution_config, print_options) . await ;
122127 }
123128}
124129
125130async fn exec_from_lines (
131+ ctx : & mut ExecutionContext ,
126132 reader : & mut BufReader < File > ,
127- execution_config : ExecutionConfig ,
128133 print_options : PrintOptions ,
129134) {
130- let mut ctx = ExecutionContext :: with_config ( execution_config) ;
131135 let mut query = "" . to_owned ( ) ;
132136
133137 for line in reader. lines ( ) {
@@ -139,7 +143,7 @@ async fn exec_from_lines(
139143 let line = line. trim_end ( ) ;
140144 query. push_str ( line) ;
141145 if line. ends_with ( ';' ) {
142- match exec_and_print ( & mut ctx, print_options. clone ( ) , query) . await {
146+ match exec_and_print ( ctx, print_options. clone ( ) , query) . await {
143147 Ok ( _) => { }
144148 Err ( err) => println ! ( "{:?}" , err) ,
145149 }
@@ -156,7 +160,7 @@ async fn exec_from_lines(
156160
157161 // run the left over query if the last statement doesn't contain ‘;’
158162 if !query. is_empty ( ) {
159- match exec_and_print ( & mut ctx, print_options, query) . await {
163+ match exec_and_print ( ctx, print_options, query) . await {
160164 Ok ( _) => { }
161165 Err ( err) => println ! ( "{:?}" , err) ,
162166 }
0 commit comments