diff options
author | Denis Isidoro <denisidoro@users.noreply.github.com> | 2021-01-18 13:03:39 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-18 13:03:39 -0300 |
commit | ee4a5660c05f17052a040c82751fc17cc56e69c4 (patch) | |
tree | a831a30d51cca169bd346eb758cd017cc2cb99fd | |
parent | 1b16de7cf5ab2865c739be04dee584d2b4ac136c (diff) |
Remove deprecated code (#453)v2.14.0
-rw-r--r-- | src/cmds/core.rs | 8 | ||||
-rw-r--r-- | src/finder.rs | 4 | ||||
-rw-r--r-- | src/structures/config.rs | 80 | ||||
-rw-r--r-- | src/structures/finder.rs | 2 | ||||
-rw-r--r-- | tests/no_prompt_cheats/cases.cheat | 22 | ||||
-rwxr-xr-x | tests/run | 5 |
6 files changed, 30 insertions, 91 deletions
diff --git a/src/cmds/core.rs b/src/cmds/core.rs index 66cd81c..3aac1e5 100644 --- a/src/cmds/core.rs +++ b/src/cmds/core.rs @@ -29,15 +29,14 @@ fn gen_core_finder_opts(config: &Config) -> Result<FinderOpts, Error> { } else { Some(format!("{} preview {{}}", filesystem::exe_string()?)) }, - autoselect: config.autoselect(), overrides: config.fzf_overrides.clone(), suggestion_type: SuggestionType::SnippetSelection, - query: if config.get_best_match() { + query: if config.best_match { None } else { config.get_query() }, - filter: if config.get_best_match() { + filter: if config.best_match { config.get_query() } else { None @@ -125,7 +124,6 @@ fn prompt_finder( }; let mut opts = FinderOpts { - autoselect: config.autoselect(), overrides: config.fzf_overrides_var.clone(), preview: Some(format!( r#"{prefix}navi preview-var "$(cat <<NAVIEOF @@ -253,7 +251,7 @@ pub fn main(config: Config) -> Result<(), Error> { }) .context("Failed getting selection and variables from finder")?; - let extractions = extract_from_selections(&raw_selection, config.get_best_match()); + let extractions = extract_from_selections(&raw_selection, config.best_match); if extractions.is_err() { return main(config); diff --git a/src/finder.rs b/src/finder.rs index 8eabef5..94c82f2 100644 --- a/src/finder.rs +++ b/src/finder.rs @@ -162,9 +162,7 @@ impl Finder for FinderChoice { ]); if let Self::Fzf = self { - if opts.autoselect { - command.arg("--select-1"); - } + command.arg("--select-1"); } match opts.suggestion_type { diff --git a/src/structures/config.rs b/src/structures/config.rs index 7388b04..0d3aa32 100644 --- a/src/structures/config.rs +++ b/src/structures/config.rs @@ -6,8 +6,6 @@ use crate::finder::FinderChoice; use clap::{crate_version, AppSettings, Clap}; use std::str::FromStr; -static mut NOTIFIED_DEPRECATION: bool = false; - impl FromStr for FinderChoice { type Err = &'static str; @@ -74,6 +72,7 @@ EXAMPLES: navi --finder 'skim' # set skim as finder, instead of fzf navi --fzf-overrides '--with-nth 1,2' # show only the comment and tag columns navi --fzf-overrides '--no-select-1' # prevent autoselection in case of single line + navi --fzf-overrides-var '--no-select-1' # same, but for variable selection navi --fzf-overrides '--nth 1,2' # only consider the first two columns for search navi --fzf-overrides '--no-exact' # use looser search algorithm"#)] #[clap(setting = AppSettings::ColorAuto)] @@ -93,17 +92,13 @@ pub struct Config { #[clap(long)] print: bool, - /// Prevents autoselection in case of single entry - #[clap(long)] - no_autoselect: bool, - /// Hides preview window #[clap(long)] pub no_preview: bool, /// Returns the best match #[clap(long)] - best_match: bool, + pub best_match: bool, /// Search for cheatsheets using the tldr-pages repository #[clap(long)] @@ -178,7 +173,7 @@ pub enum Command { /// Typed text variable: String, }, - /// Shows the path for shell widget files + /// Outputs shell widget source code Widget { #[clap(possible_values = &["bash", "zsh", "fish"], case_insensitive = true, default_value = "bash")] shell: Shell, @@ -219,25 +214,6 @@ pub enum AlfredCommand { Check, } -fn deprecated(syntax: &str) { - unsafe { - if NOTIFIED_DEPRECATION { - return; - } - eprintln!( - r"⚠️ The following syntax has been DEPRECATED: -navi {} - -Please check `navi --help` for more info on how to achieve the same result with the new syntax. - -The deprecated syntax will be removed in the first version released on 2021! ⚠️ -", - syntax - ); - NOTIFIED_DEPRECATION = true; - } -} - pub enum Source { FILESYSTEM(Option<String>), TLDR(String), @@ -272,48 +248,18 @@ impl Config { } pub fn get_query(&self) -> Option<String> { - match &self.cmd { - Some(Command::Query { query }) => { - deprecated("query <query>"); - Some(query.clone()) - } - Some(Command::Best { query, .. }) => { - deprecated("best <query>"); - Some(query.clone()) - } - _ => { - let q = self.query.clone(); - if q.is_some() { - return q; - } - if self.get_best_match() { - match self.source() { - Source::TLDR(q) => Some(q), - Source::CHEATSH(q) => Some(q), - _ => Some(String::from("")), - } - } else { - None - } - } + let q = self.query.clone(); + if q.is_some() { + return q; } - } - - pub fn get_best_match(&self) -> bool { - if let Some(Command::Best { .. }) = &self.cmd { - deprecated("best <query>"); - true - } else { - self.best_match - } - } - - pub fn autoselect(&self) -> bool { - if self.no_autoselect { - deprecated("--no-autoselect"); - false + if self.best_match { + match self.source() { + Source::TLDR(q) => Some(q), + Source::CHEATSH(q) => Some(q), + _ => Some(String::from("")), + } } else { - true + None } } } diff --git a/src/structures/finder.rs b/src/structures/finder.rs index aff8732..717fed8 100644 --- a/src/structures/finder.rs +++ b/src/structures/finder.rs @@ -5,7 +5,6 @@ pub struct Opts { pub prompt: Option<String>, pub preview: Option<String>, pub preview_window: Option<String>, - pub autoselect: bool, pub overrides: Option<String>, pub global: bool, pub header_lines: u8, @@ -21,7 +20,6 @@ impl Default for Opts { Self { query: None, filter: None, - autoselect: true, preview: None, preview_window: None, global: false, diff --git a/tests/no_prompt_cheats/cases.cheat b/tests/no_prompt_cheats/cases.cheat index fb73acb..5775d37 100644 --- a/tests/no_prompt_cheats/cases.cheat +++ b/tests/no_prompt_cheats/cases.cheat @@ -8,17 +8,6 @@ echo "foo" # sed with replacement -> "172.17.0.2" echo "8.8.8.8 via 172.17.0.1 dev eth0 src 172.17.0.2" | sed -E 's/.*src ([0-9.]+).*/\1/p' | head -n1 -# multiline command: no backslash -> "foo\nbar" -echo "foo" -echo "bar" - -# multiline command: with backslash -> "lorem ipsum\nno match" -echo 'lorem ipsum' -echo "foo" \ - | grep -q "bar" \ - && echo "match" \ - || echo "no match" - # 2nd column with default delimiter -> "rust is cool" echo "<language> is cool" @@ -37,6 +26,17 @@ echo "<x> <x2> <y> <x>" # nested unused value -> "path: /my/pictures" echo "path: <pictures_folder>" +# multiline command: no backslash -> "foo\nbar" +echo "foo" +echo "bar" + +# multiline command: with backslash -> "lorem ipsum\nno match" +echo 'lorem ipsum' +echo "foo" \ + | grep -q "bar" \ + && echo "match" \ + || echo "no match" + $ x: echo '2' $ x2: echo "$((x+10))" $ y: echo 'a' @@ -20,8 +20,7 @@ _navi() { } _navi_cases() { - local filter="$*" - filter="${filter::-2}" + local -r filter="${1::-2}" _navi --query "$filter" --best-match } @@ -60,7 +59,7 @@ _navi_cheatsh() { } _navi_widget() { - _navi widget "$1" \ + echo "$(_navi widget "$1")" \ | grep -q "#!/usr/bin/env $1" } |