diff --git a/src/habitmgr.rs b/src/habitmgr.rs index 989ea34..54bae8d 100644 --- a/src/habitmgr.rs +++ b/src/habitmgr.rs @@ -74,7 +74,7 @@ impl HabitMgr self.habits = serde_json::from_reader(habits_reader).unwrap(); } - fn write_habits(&self) + fn export_habits(&self) { let habits_file = OpenOptions::new() .truncate(true) @@ -95,7 +95,7 @@ impl HabitMgr { self.import_habits(); self.habits.push(Habit::new(name.clone(), bad, weight)); - self.write_habits(); + self.export_habits(); println!("New habit {} added.", &name); } @@ -104,10 +104,32 @@ impl HabitMgr { self.import_habits(); let old_habit = self.habits.remove(id); - self.write_habits(); + self.export_habits(); println!("Removed habit {}", old_habit.get_name()); } + pub fn modify(&mut self, id:usize, + name:Option, + bad:Option, + weight:Option, + _days:Option) + { + self.import_habits(); + if name.is_some() + { + self.habits[id].set_name(name.unwrap()); + } + if bad.is_some() + { + self.habits[id].set_bad(bad.unwrap()); + } + if weight.is_some() + { + self.habits[id].set_weight(weight.unwrap()); + } + self.export_habits(); + } + pub fn list(&mut self, _all:bool, _verbose:bool) { self.import_habits();