@@ -22,6 +22,7 @@ use datafusion_cli::{
22
22
context:: Context , exec, print_format:: PrintFormat , print_options:: PrintOptions ,
23
23
DATAFUSION_CLI_VERSION ,
24
24
} ;
25
+ use dirs;
25
26
use mimalloc:: MiMalloc ;
26
27
use std:: env;
27
28
use std:: path:: Path ;
@@ -55,17 +56,17 @@ struct Args {
55
56
help = "Execute commands from file(s), then exit" ,
56
57
validator( is_valid_file)
57
58
) ]
58
- file_exit : Vec < String > ,
59
+ file : Vec < String > ,
59
60
60
61
#[ clap(
61
- short,
62
+ short = 'r' ,
62
63
long,
63
64
multiple_values = true ,
64
- help = "Execute commands from file(s) " ,
65
+ help = "Run the provided files on startup instead of ~/.datafusionrc " ,
65
66
validator( is_valid_file) ,
66
67
conflicts_with = "file"
67
68
) ]
68
- file_run : Vec < String > ,
69
+ rc : Option < Vec < String > > ,
69
70
70
71
#[ clap( long, arg_enum, default_value_t = PrintFormat :: Table ) ]
71
72
format : PrintFormat ,
@@ -114,14 +115,31 @@ pub async fn main() -> Result<()> {
114
115
quiet : args. quiet ,
115
116
} ;
116
117
117
- let files_to_run_then_quit = args. file_exit ;
118
- let files_to_run = args. file_run ;
119
- if !files_to_run_then_quit. is_empty ( ) {
120
- exec:: exec_from_files ( files_to_run_then_quit, & mut ctx, & print_options) . await
118
+ let files = args. file ;
119
+ let rc = match args. rc {
120
+ Some ( file) => file,
121
+ None => {
122
+ let mut files = Vec :: new ( ) ;
123
+ let home = dirs:: home_dir ( ) ;
124
+ match home {
125
+ Some ( p) => {
126
+ let home_rc = p. join ( ".datafusionrc" ) ;
127
+ if home_rc. exists ( ) {
128
+ files. push ( String :: from (
129
+ home_rc. into_os_string ( ) . into_string ( ) . unwrap ( ) ,
130
+ ) ) ;
131
+ }
132
+ }
133
+ None => ( ) ,
134
+ }
135
+ files
136
+ }
137
+ } ;
138
+ if !files. is_empty ( ) {
139
+ exec:: exec_from_files ( files, & mut ctx, & print_options) . await
121
140
} else {
122
- if !files_to_run. is_empty ( ) {
123
- println ! ( "Running files: {}" , & files_to_run. join( "," ) ) ;
124
- exec:: exec_from_files ( files_to_run, & mut ctx, & print_options) . await
141
+ if !rc. is_empty ( ) {
142
+ exec:: exec_from_files ( rc, & mut ctx, & print_options) . await
125
143
}
126
144
exec:: exec_from_repl ( & mut ctx, & mut print_options) . await ;
127
145
}
0 commit comments