SHARE
TWEET

Untitled

a guest Sep 15th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::env;
  2.  
  3. type Error = &'static str;
  4.  
  5. fn query_only_excluded(_: &[String]) -> Result<Vec<String>, Error> { Ok(vec![]) }
  6. fn query_no_required  (_: &[String], _: &[String]) -> Result<Vec<String>, Error> { Ok(vec![]) }
  7. fn query_with_required(_: &[String], _: &[String], _: &[String]) -> Result<Vec<String>, Error> { Ok(vec![]) }
  8.  
  9. fn query_tags() -> Result<Vec<String>, Error> {
  10.   let mut excluded_tags = vec![];
  11.   let mut required_tags = vec![];
  12.   let mut prefered_tags = vec![];
  13.  
  14.   for arg in env::args() {
  15.     match (arg.get(..1), arg.get(1..)) {
  16.       (Some("-"), Some(rst)) => excluded_tags.push(rst.to_string()),
  17.       (Some("+"), Some(rst)) => required_tags.push(rst.to_string()),
  18.       _                      => prefered_tags.push(arg),
  19.     }
  20.   }
  21.  
  22.   match (&required_tags[..], &prefered_tags[..], &excluded_tags[..]) {
  23.     ([], [], []) => Err("No Input"),
  24.     ([], [], ex) => Ok(query_only_excluded(        ex)?),
  25.     ([], pr, ex) => Ok(query_no_required  (    pr, ex)?),
  26.     (re, pr, ex) => Ok(query_with_required(re, pr, ex)?),
  27.   }
  28. }
  29.  
  30. fn main() -> Result<(), Error> {
  31.   let files = query_tags()?;
  32.   println!("{:?}", files);
  33.   Ok(())
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top