Skip to content

Commit

Permalink
Remove deprecated code (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Jan 18, 2021
1 parent 1b16de7 commit ee4a566
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 91 deletions.
8 changes: 3 additions & 5 deletions src/cmds/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
80 changes: 13 additions & 67 deletions src/structures/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)]
Expand All @@ -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)]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/structures/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,7 +20,6 @@ impl Default for Opts {
Self {
query: None,
filter: None,
autoselect: true,
preview: None,
preview_window: None,
global: false,
Expand Down
22 changes: 11 additions & 11 deletions tests/no_prompt_cheats/cases.cheat
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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'
Expand Down
5 changes: 2 additions & 3 deletions tests/run
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ _navi() {
}

_navi_cases() {
local filter="$*"
filter="${filter::-2}"
local -r filter="${1::-2}"
_navi --query "$filter" --best-match
}

Expand Down Expand Up @@ -60,7 +59,7 @@ _navi_cheatsh() {
}

_navi_widget() {
_navi widget "$1" \
echo "$(_navi widget "$1")" \
| grep -q "#!/usr/bin/env $1"
}

Expand Down

0 comments on commit ee4a566

Please sign in to comment.