diff --git a/pttodoer/src/main.rs b/pttodoer/src/main.rs index 5fa68d2..47007ff 100644 --- a/pttodoer/src/main.rs +++ b/pttodoer/src/main.rs @@ -9,7 +9,21 @@ use clap::Parser; fn main() { let flags = Flags::new(); - let db = DB::new(flags.path).unwrap(); + + let mut db = DB::new(flags.path).unwrap(); + + match flags.add { + Some(s) => { + let t = match flags.add_schedule { + Some(sch) => Task::from_string_schedule(s, sch), + None => Task::from_string(s), + }; + db.0[0].tasks.0.push(t); + // TODO save + }, + _ => {}, + }; + println!("{}", db.due().to_string()); } @@ -326,6 +340,19 @@ impl Task { Task(serde_yaml::Mapping::new()) } + pub fn from_string(s: String) -> Task { + let mut t = Task::new(); + t.set("is".to_string(), s); + t + } + + pub fn from_string_schedule(s: String, schedule: String) -> Task { + let mut t = Task::new(); + t.set("is".to_string(), s); + t.set("schedule".to_string(), schedule); + t + } + pub fn from_reader(mut r: impl std::io::Read) -> Result { let mut buff = String::new(); match r.read_to_string(&mut buff) {