Skip to content

Commit 5597e4c

Browse files
Move to .datafusionrc
1 parent cf43b17 commit 5597e4c

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

datafusion-cli/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ datafusion = { path = "../datafusion", version = "7.0.0" }
3535
arrow = { version = "9.1" }
3636
ballista = { path = "../ballista/rust/client", version = "0.6.0", optional=true }
3737
env_logger = "0.9"
38-
mimalloc = { version = "*", default-features = false }
38+
mimalloc = { version = "*", default-features = false }
39+
dirs = "4.0.0"

datafusion-cli/src/main.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use datafusion_cli::{
2222
context::Context, exec, print_format::PrintFormat, print_options::PrintOptions,
2323
DATAFUSION_CLI_VERSION,
2424
};
25+
use dirs;
2526
use mimalloc::MiMalloc;
2627
use std::env;
2728
use std::path::Path;
@@ -55,17 +56,17 @@ struct Args {
5556
help = "Execute commands from file(s), then exit",
5657
validator(is_valid_file)
5758
)]
58-
file_exit: Vec<String>,
59+
file: Vec<String>,
5960

6061
#[clap(
61-
short,
62+
short = 'r',
6263
long,
6364
multiple_values = true,
64-
help = "Execute commands from file(s)",
65+
help = "Run the provided files on startup instead of ~/.datafusionrc",
6566
validator(is_valid_file),
6667
conflicts_with = "file"
6768
)]
68-
file_run: Vec<String>,
69+
rc: Option<Vec<String>>,
6970

7071
#[clap(long, arg_enum, default_value_t = PrintFormat::Table)]
7172
format: PrintFormat,
@@ -114,14 +115,31 @@ pub async fn main() -> Result<()> {
114115
quiet: args.quiet,
115116
};
116117

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
121140
} 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
125143
}
126144
exec::exec_from_repl(&mut ctx, &mut print_options).await;
127145
}

0 commit comments

Comments
 (0)