mirror of
https://github.com/FliegendeWurst/ripgrep-all.git
synced 2024-11-24 12:24:56 +00:00
allow adapters to be disabled by default
This commit is contained in:
parent
c8f346c4dd
commit
d1b55e80b7
@ -9,7 +9,7 @@ use crate::matching::*;
|
|||||||
use crate::preproc::PreprocConfig;
|
use crate::preproc::PreprocConfig;
|
||||||
use failure::*;
|
use failure::*;
|
||||||
use log::*;
|
use log::*;
|
||||||
use regex::{Regex};
|
use regex::{Regex, RegexSet};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
@ -69,13 +69,9 @@ pub struct AdaptInfo<'a> {
|
|||||||
pub config: PreprocConfig<'a>,
|
pub config: PreprocConfig<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extension_to_regex(extension: &str) -> Regex {
|
pub fn get_adapters() -> (Vec<Rc<dyn FileAdapter>>, Vec<Rc<dyn FileAdapter>>) {
|
||||||
Regex::new(&format!(".*\\.{}", ®ex::escape(extension))).expect("we know this regex compiles")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_adapters() -> Vec<Rc<dyn FileAdapter>> {
|
|
||||||
// order in descending priority
|
// order in descending priority
|
||||||
let adapters: Vec<Rc<dyn FileAdapter>> = vec![
|
let enabled_adapters: Vec<Rc<dyn FileAdapter>> = vec![
|
||||||
Rc::new(ffmpeg::FFmpegAdapter),
|
Rc::new(ffmpeg::FFmpegAdapter),
|
||||||
Rc::new(pandoc::PandocAdapter),
|
Rc::new(pandoc::PandocAdapter),
|
||||||
Rc::new(poppler::PopplerAdapter),
|
Rc::new(poppler::PopplerAdapter),
|
||||||
@ -83,16 +79,27 @@ pub fn get_adapters() -> Vec<Rc<dyn FileAdapter>> {
|
|||||||
Rc::new(tar::TarAdapter),
|
Rc::new(tar::TarAdapter),
|
||||||
Rc::new(sqlite::SqliteAdapter),
|
Rc::new(sqlite::SqliteAdapter),
|
||||||
];
|
];
|
||||||
adapters
|
let disabled_adapters: Vec<Rc<dyn FileAdapter>> = vec![
|
||||||
|
//Rc::new()
|
||||||
|
];
|
||||||
|
(enabled_adapters, disabled_adapters)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* filter adapters by given names:
|
||||||
|
*
|
||||||
|
* - "" means use default enabled adapter list
|
||||||
|
* - "-a,b" means use default list except for a and b
|
||||||
|
* - "+a,b" means use default list but also a and b
|
||||||
|
*/
|
||||||
pub fn get_adapters_filtered<T: AsRef<str>>(
|
pub fn get_adapters_filtered<T: AsRef<str>>(
|
||||||
adapter_names: &[T],
|
adapter_names: &[T],
|
||||||
) -> Fallible<Vec<Rc<dyn FileAdapter>>> {
|
) -> Fallible<Vec<Rc<dyn FileAdapter>>> {
|
||||||
let all_adapters = get_adapters();
|
let (def_enabled_adapters, def_disabled_adapters) = get_adapters();
|
||||||
let adapters = if !adapter_names.is_empty() {
|
let adapters = if !adapter_names.is_empty() {
|
||||||
let adapters_map: HashMap<_, _> = all_adapters
|
let adapters_map: HashMap<_, _> = def_enabled_adapters
|
||||||
.iter()
|
.iter()
|
||||||
|
.chain(def_disabled_adapters.iter())
|
||||||
.map(|e| (e.metadata().name.clone(), e.clone()))
|
.map(|e| (e.metadata().name.clone(), e.clone()))
|
||||||
.collect();
|
.collect();
|
||||||
let mut adapters = vec![];
|
let mut adapters = vec![];
|
||||||
@ -102,7 +109,10 @@ pub fn get_adapters_filtered<T: AsRef<str>>(
|
|||||||
if i == 0 && (name.starts_with('-')) {
|
if i == 0 && (name.starts_with('-')) {
|
||||||
subtractive = true;
|
subtractive = true;
|
||||||
name = &name[1..];
|
name = &name[1..];
|
||||||
adapters = all_adapters.clone();
|
adapters = def_enabled_adapters.clone();
|
||||||
|
} else if i == 0 && (name.starts_with('+')) {
|
||||||
|
name = &name[1..];
|
||||||
|
adapters = def_enabled_adapters.clone();
|
||||||
}
|
}
|
||||||
if subtractive {
|
if subtractive {
|
||||||
let inx = adapters
|
let inx = adapters
|
||||||
@ -121,7 +131,7 @@ pub fn get_adapters_filtered<T: AsRef<str>>(
|
|||||||
}
|
}
|
||||||
adapters
|
adapters
|
||||||
} else {
|
} else {
|
||||||
all_adapters
|
def_enabled_adapters
|
||||||
};
|
};
|
||||||
debug!(
|
debug!(
|
||||||
"Chosen adapters: {}",
|
"Chosen adapters: {}",
|
||||||
|
Loading…
Reference in New Issue
Block a user