mirror of
https://github.com/denisidoro/navi
synced 2024-11-24 20:43:06 +00:00
Remove unnecessary uses of vector of files (#507)
This commit is contained in:
parent
d5d939bc96
commit
ab7289e3aa
4 changed files with 18 additions and 24 deletions
|
@ -115,9 +115,9 @@ NAVIEOF
|
|||
opts.suggestion_type = SuggestionType::Disabled;
|
||||
};
|
||||
|
||||
let (output, _) = config
|
||||
let (output, _, _) = config
|
||||
.finder
|
||||
.call(opts, &mut Vec::new(), |stdin, _| {
|
||||
.call(opts, |stdin, _| {
|
||||
stdin
|
||||
.write_all(suggestions.as_bytes())
|
||||
.context("Could not write to finder's stdin")?;
|
||||
|
@ -178,7 +178,7 @@ fn replace_variables_from_snippet(
|
|||
pub fn act(
|
||||
extractions: Result<extractor::Output, Error>,
|
||||
config: Config,
|
||||
files: &mut Vec<String>,
|
||||
files: Vec<String>,
|
||||
variables: Option<VariableMap>,
|
||||
) -> Result<(), Error> {
|
||||
let (key, tags, comment, snippet, file_index) = extractions.unwrap();
|
||||
|
|
|
@ -46,11 +46,9 @@ fn gen_core_finder_opts(config: &Config) -> Result<FinderOpts, Error> {
|
|||
pub fn main(config: Config) -> Result<(), Error> {
|
||||
let opts = gen_core_finder_opts(&config).context("Failed to generate finder options")?;
|
||||
|
||||
let mut files = Vec::new();
|
||||
|
||||
let (raw_selection, variables) = config
|
||||
let (raw_selection, variables, files) = config
|
||||
.finder
|
||||
.call(opts, &mut files, |stdin, files| {
|
||||
.call(opts, |stdin, files| {
|
||||
let mut writer = writer::terminal::Writer::new();
|
||||
|
||||
let fetcher: Box<dyn Fetcher> = match config.source() {
|
||||
|
@ -78,7 +76,7 @@ pub fn main(config: Config) -> Result<(), Error> {
|
|||
return main(config);
|
||||
}
|
||||
|
||||
actor::act(extractions, config, &mut files, variables)?;
|
||||
actor::act(extractions, config, files, variables)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ pub fn browse(finder: &FinderChoice) -> Result<(), Error> {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
let (repo, _) = finder
|
||||
.call(opts, &mut Vec::new(), |stdin, _| {
|
||||
let (repo, _, _) = finder
|
||||
.call(opts, |stdin, _| {
|
||||
stdin
|
||||
.write_all(repos.as_bytes())
|
||||
.context("Unable to prompt featured repositories")?;
|
||||
|
@ -60,8 +60,8 @@ pub fn ask_if_should_import_all(finder: &FinderChoice) -> Result<bool, Error> {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
let (response, _) = finder
|
||||
.call(opts, &mut Vec::new(), |stdin, _| {
|
||||
let (response, _, _) = finder
|
||||
.call(opts, |stdin, _| {
|
||||
stdin
|
||||
.write_all(b"Yes\nNo")
|
||||
.context("Unable to writer alternatives")?;
|
||||
|
@ -105,8 +105,8 @@ pub fn add(uri: String, finder: &FinderChoice) -> Result<(), Error> {
|
|||
let files = if should_import_all {
|
||||
all_files
|
||||
} else {
|
||||
let (files, _) = finder
|
||||
.call(opts, &mut Vec::new(), |stdin, _| {
|
||||
let (files, _, _) = finder
|
||||
.call(opts, |stdin, _| {
|
||||
stdin
|
||||
.write_all(all_files.as_bytes())
|
||||
.context("Unable to prompt cheats to import")?;
|
||||
|
|
|
@ -19,12 +19,7 @@ pub enum FinderChoice {
|
|||
}
|
||||
|
||||
pub trait Finder {
|
||||
fn call<F>(
|
||||
&self,
|
||||
opts: Opts,
|
||||
files: &mut Vec<String>,
|
||||
stdin_fn: F,
|
||||
) -> Result<(String, Option<VariableMap>), Error>
|
||||
fn call<F>(&self, opts: Opts, stdin_fn: F) -> Result<(String, Option<VariableMap>, Vec<String>), Error>
|
||||
where
|
||||
F: Fn(&mut process::ChildStdin, &mut Vec<String>) -> Result<Option<VariableMap>, Error>;
|
||||
}
|
||||
|
@ -50,9 +45,8 @@ impl Finder for FinderChoice {
|
|||
fn call<F>(
|
||||
&self,
|
||||
finder_opts: Opts,
|
||||
files: &mut Vec<String>,
|
||||
stdin_fn: F,
|
||||
) -> Result<(String, Option<VariableMap>), Error>
|
||||
) -> Result<(String, Option<VariableMap>, Vec<String>), Error>
|
||||
where
|
||||
F: Fn(&mut process::ChildStdin, &mut Vec<String>) -> Result<Option<VariableMap>, Error>,
|
||||
{
|
||||
|
@ -174,11 +168,13 @@ impl Finder for FinderChoice {
|
|||
.stdin
|
||||
.as_mut()
|
||||
.ok_or_else(|| anyhow!("Unable to acquire stdin of finder"))?;
|
||||
let result_map = stdin_fn(stdin, files).context("Failed to pass data to finder")?;
|
||||
|
||||
let mut files = vec![];
|
||||
let result_map = stdin_fn(stdin, &mut files).context("Failed to pass data to finder")?;
|
||||
|
||||
let out = child.wait_with_output().context("Failed to wait for finder")?;
|
||||
|
||||
let output = parse(out, finder_opts).context("Unable to get output")?;
|
||||
Ok((output, result_map))
|
||||
Ok((output, result_map, files))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue