mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 11:33:10 +00:00
Fix best command (#210)
This commit is contained in:
parent
fe26b00953
commit
dc4fe98f56
4 changed files with 11 additions and 7 deletions
|
@ -8,6 +8,6 @@ pub fn main(query: String, args: Vec<String>, config: Config) -> Result<(), Box<
|
||||||
if !args.is_empty() {
|
if !args.is_empty() {
|
||||||
cmds::aux::abort("passing arguments to 'navi best'", 201)
|
cmds::aux::abort("passing arguments to 'navi best'", 201)
|
||||||
} else {
|
} else {
|
||||||
cmds::core::main(Variant::Filter(query), config)
|
cmds::core::main(Variant::Filter(query), config, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,9 +36,13 @@ fn gen_core_fzf_opts(variant: Variant, config: &Config) -> fzf::Opts {
|
||||||
opts
|
opts
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_from_selections(raw_output: &str) -> (&str, &str, &str) {
|
fn extract_from_selections(raw_output: &str, contains_key: bool) -> (&str, &str, &str) {
|
||||||
let mut lines = raw_output.split('\n');
|
let mut lines = raw_output.split('\n');
|
||||||
let key = lines.next().unwrap();
|
let key = if contains_key {
|
||||||
|
lines.next().unwrap()
|
||||||
|
} else {
|
||||||
|
"enter"
|
||||||
|
};
|
||||||
let mut parts = lines.next().unwrap().split('\t');
|
let mut parts = lines.next().unwrap().split('\t');
|
||||||
parts.next();
|
parts.next();
|
||||||
parts.next();
|
parts.next();
|
||||||
|
@ -127,7 +131,7 @@ fn replace_variables_from_snippet(
|
||||||
interpolated_snippet
|
interpolated_snippet
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main(variant: Variant, config: Config) -> Result<(), Box<dyn Error>> {
|
pub fn main(variant: Variant, config: Config, contains_key: bool) -> Result<(), Box<dyn Error>> {
|
||||||
let (output, variables) = fzf::call(gen_core_fzf_opts(variant, &config), |stdin| {
|
let (output, variables) = fzf::call(gen_core_fzf_opts(variant, &config), |stdin| {
|
||||||
Some(cheat::read_all(&config, stdin))
|
Some(cheat::read_all(&config, stdin))
|
||||||
});
|
});
|
||||||
|
@ -135,7 +139,7 @@ pub fn main(variant: Variant, config: Config) -> Result<(), Box<dyn Error>> {
|
||||||
match output.status.code() {
|
match output.status.code() {
|
||||||
Some(0) => {
|
Some(0) => {
|
||||||
let raw_output = String::from_utf8(output.stdout)?;
|
let raw_output = String::from_utf8(output.stdout)?;
|
||||||
let (key, tags, snippet) = extract_from_selections(&raw_output[..]);
|
let (key, tags, snippet) = extract_from_selections(&raw_output[..], contains_key);
|
||||||
let interpolated_snippet =
|
let interpolated_snippet =
|
||||||
replace_variables_from_snippet(snippet, tags, variables.unwrap(), &config);
|
replace_variables_from_snippet(snippet, tags, variables.unwrap(), &config);
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,5 @@ use crate::cmds::core::Variant;
|
||||||
use crate::option::Config;
|
use crate::option::Config;
|
||||||
|
|
||||||
pub fn main(query: String, config: Config) -> Result<(), Box<dyn Error>> {
|
pub fn main(query: String, config: Config) -> Result<(), Box<dyn Error>> {
|
||||||
cmds::core::main(Variant::Query(query), config)
|
cmds::core::main(Variant::Query(query), config, true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
_ => {
|
_ => {
|
||||||
let mut config = option::parse();
|
let mut config = option::parse();
|
||||||
match config.cmd.as_mut() {
|
match config.cmd.as_mut() {
|
||||||
None => cmds::core::main(Variant::Core, config),
|
None => cmds::core::main(Variant::Core, config, true),
|
||||||
Some(c) => match c {
|
Some(c) => match c {
|
||||||
Command::Query { query } => cmds::query::main(query.clone(), config),
|
Command::Query { query } => cmds::query::main(query.clone(), config),
|
||||||
Command::Best { query, args } => {
|
Command::Best { query, args } => {
|
||||||
|
|
Loading…
Reference in a new issue