From e32e0f12455bdd1e30b7ef5bb2f1616b3123157a Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Thu, 12 Mar 2020 19:04:47 -0300 Subject: Fix delimiter (#239) Fixes #230 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/cheat.rs | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1874236..0e2176b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -89,7 +89,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "navi" -version = "2.0.7" +version = "2.0.8" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "raw_tty 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 5be37a1..5f6dc14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "navi" -version = "2.0.7" +version = "2.0.8" authors = ["Denis Isidoro "] edition = "2018" diff --git a/src/cheat.rs b/src/cheat.rs index 5789894..9aeafee 100644 --- a/src/cheat.rs +++ b/src/cheat.rs @@ -24,6 +24,10 @@ fn gen_snippet(snippet: &str, line: &str) -> String { } } +fn remove_quote(txt: &str) -> String { + txt.replace('"', "").replace('\'', "") +} + fn parse_opts(text: &str) -> SuggestionOpts { let mut header_lines: u8 = 0; let mut column: Option = None; @@ -36,10 +40,10 @@ fn parse_opts(text: &str) -> SuggestionOpts { match p { "--multi" => multi = true, "--header" | "--headers" | "--header-lines" => { - header_lines = parts.next().unwrap().parse::().unwrap() + header_lines = remove_quote(parts.next().unwrap()).parse::().unwrap() } - "--column" => column = Some(parts.next().unwrap().parse::().unwrap()), - "--delimiter" => delimiter = Some(parts.next().unwrap().to_string()), + "--column" => column = Some(remove_quote(parts.next().unwrap()).parse::().unwrap()), + "--delimiter" => delimiter = Some(remove_quote(parts.next().unwrap()).to_string()), _ => (), } } @@ -134,8 +138,11 @@ fn read_file( pub fn read_all(config: &Config, stdin: &mut std::process::ChildStdin) -> HashMap { let mut variables: HashMap = HashMap::new(); - let fallback = filesystem::pathbuf_to_string(filesystem::cheat_pathbuf().unwrap()); - let folders_str = config.path.as_ref().unwrap_or(&fallback); + let mut fallback: String = String::from(""); + let folders_str = config.path.as_ref().unwrap_or_else(|| { + fallback = filesystem::pathbuf_to_string(filesystem::cheat_pathbuf().unwrap()); + &fallback + }); let folders = folders_str.split(':'); for folder in folders { -- cgit v1.2.3