Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: add rfd crate & when input is rfd use file dialog #1852

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
552 changes: 546 additions & 6 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -220,6 +220,7 @@ uuid = { version = "1", features = ["v4"] }
url = "2.5"
vader_sentiment = { version = "0.1", optional = true }
whatlang = { version = "0.16", optional = true }
rfd = "0.14.1"

[target.'cfg(not(target_arch = "aarch64"))'.dependencies]
simdutf8 = "0.1"
31 changes: 31 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ use std::{

use log::{debug, info, warn};
use qsv_sniffer::{SampleSize, Sniffer};
use rfd::FileDialog;
use serde::de::{Deserialize, Deserializer, Error};

use crate::{
@@ -123,6 +124,36 @@ impl Config {
// (Some(PathBuf::from(s)), delim, snappy)
// },
Some(ref s) if &**s == "-" => (None, default_delim, false),
Some(ref s) if &**s == "rfd" => {
if let Some(path) = FileDialog::new().set_directory("/").pick_file() {
let file_extension = path
.extension()
.unwrap_or_default()
.to_str()
.unwrap()
.to_ascii_lowercase();
let mut snappy = false;
let delim = if file_extension == "tsv" || file_extension == "tab" {
b'\t'
} else if file_extension == "csv" {
b','
} else {
let filename = path.file_name().unwrap().to_str().unwrap();
if filename.ends_with(".csv.sz") {
snappy = true;
b','
} else if filename.ends_with(".tsv.sz") || filename.ends_with(".tab.sz") {
snappy = true;
b'\t'
} else {
default_delim
}
};
(Some(path), delim, snappy || file_extension.ends_with("sz"))
} else {
panic!("No file selected from file dialog.")
}
},
Some(ref s) => {
let path = PathBuf::from(s);
let file_extension = path
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
@@ -1606,7 +1606,7 @@ pub fn process_input(
// check the input files
for path in work_input {
// does the input file exist?
if !path.exists() {
if !path.exists() && path != PathBuf::from("rfd") {
return fail_clierror!("Input file '{}' does not exist", path.display());
}