classy_sync/
argument_parser.rs1use std::collections::{HashMap, HashSet};
2
3#[derive(Debug)]
13pub enum SyncResources {
14 Everything,
15 Select(SelectSyncOptions),
16}
17
18#[derive(Debug)]
19pub enum CollectionType {
20 AllSchoolData,
21 SelectTermData(HashSet<String>),
22}
23
24#[derive(Debug)]
25pub struct SelectSyncOptions {
26 school_to_collection: HashMap<String, CollectionType>,
27}
28
29impl SelectSyncOptions {
30 pub fn from_input(input: String) -> SelectSyncOptions {
31 let schools_or_terms: Vec<String> = input.split(";").map(|s| s.to_string()).collect();
32 let mut school_to_collection: HashMap<String, CollectionType> = HashMap::new();
33
34 for schoool_or_term in schools_or_terms.into_iter() {
35 let school_and_maybe_term: Vec<&str> =
36 schoool_or_term.split(",").map(|s| s.trim()).collect();
37 assert_eq!(school_and_maybe_term.len(), 1, "No school given?");
38 let school = school_and_maybe_term[0].to_string();
39
40 if school_and_maybe_term.len() == 1 {
42 school_to_collection.insert(school.to_string(), CollectionType::AllSchoolData);
43 continue;
44 }
45
46 school_to_collection.insert(
48 school.to_string(),
49 CollectionType::SelectTermData(
50 school_and_maybe_term[1..]
51 .iter()
52 .map(|t| t.to_string())
53 .collect(),
54 ),
55 );
56 }
57 SelectSyncOptions {
58 school_to_collection,
59 }
60 }
61
62 pub fn get_collections(&self) -> &HashMap<String, CollectionType> {
63 &self.school_to_collection
64 }
65}