浏览代码

Allow multiple ValuePatternQueries

Johannes Hofmann 7 年前
父节点
当前提交
3a96a3c2eb
共有 2 个文件被更改,包括 22 次插入7 次删除
  1. 2
    0
      src/args.rs
  2. 20
    7
      src/config.rs

+ 2
- 0
src/args.rs 查看文件

@@ -32,6 +32,8 @@ pub fn parse<'a>() -> clap::ArgMatches<'a> {
32 32
             .short("s")
33 33
             .long("search")
34 34
             .value_name("PATTERN")
35
+            .number_of_values(1)
36
+            .multiple(true)
35 37
             .help("Search for places which match the given pattern")
36 38
             .takes_value(true))
37 39
         .arg(Arg::with_name("keyval")

+ 20
- 7
src/config.rs 查看文件

@@ -28,7 +28,7 @@ pub struct Config {
28 28
     tile_cache_dir: PathBuf,
29 29
     sources: Vec<(String, TileSource)>,
30 30
     pbf_path: Option<PathBuf>,
31
-    search_pattern: Option<String>,
31
+    search_patterns: Vec<String>,
32 32
     keyval: Vec<(String, String)>,
33 33
     keyvalregex: Vec<(String, String)>,
34 34
     fps: f64,
@@ -68,7 +68,12 @@ impl Config {
68 68
     }
69 69
 
70 70
     fn merge_arg_matches<'a>(&mut self, matches: &clap::ArgMatches<'a>) {
71
-        self.search_pattern = matches.value_of("search").map(|s| s.to_string());
71
+        self.search_patterns = matches.values_of("search").map_or_else(
72
+            || vec![],
73
+            |p| {
74
+                p.map(|s| s.to_string()).collect()
75
+            },
76
+        );
72 77
 
73 78
         self.keyval = matches.values_of("keyval").map_or_else(
74 79
             || vec![],
@@ -261,7 +266,7 @@ impl Config {
261 266
                         tile_cache_dir,
262 267
                         sources: vec![],
263 268
                         pbf_path,
264
-                        search_pattern: None,
269
+                        search_patterns: vec![],
265 270
                         keyval: vec![],
266 271
                         keyvalregex: vec![],
267 272
                         fps,
@@ -421,8 +426,8 @@ impl Config {
421 426
         self.pbf_path.as_ref().map(|p| p.as_path())
422 427
     }
423 428
 
424
-    pub fn search_pattern(&self) -> Option<&str> {
425
-        self.search_pattern.as_ref().map(|s| s.as_str())
429
+    pub fn search_patterns(&self) -> &[String] {
430
+        self.search_patterns.as_slice()
426 431
     }
427 432
 
428 433
     pub fn keyval(&self) -> &[(String, String)] {
@@ -434,9 +439,17 @@ impl Config {
434 439
     }
435 440
 
436 441
     pub fn query_args(&self) -> Option<QueryArgs> {
437
-        match (&self.search_pattern, self.keyval.first(), self.keyvalregex.first()) {
442
+        match (&self.search_patterns.first(), self.keyval.first(), self.keyvalregex.first()) {
438 443
             (&Some(ref pattern), None, None) => Some(
439
-                QueryArgs::ValuePattern(pattern.to_string())
444
+                if self.search_patterns.len() == 1 {
445
+                    QueryArgs::ValuePattern(pattern.to_string())
446
+                } else {
447
+                    QueryArgs::Intersection(
448
+                        self.search_patterns.iter()
449
+                            .map(|s| QueryArgs::ValuePattern(s.to_string()))
450
+                            .collect()
451
+                    )
452
+                }
440 453
             ),
441 454
             (&None, Some(keyval), None) => Some(
442 455
                 if self.keyval.len() == 1 {