diff --git a/README.md b/README.md index 2fd9618..e47a1a0 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,12 @@ is specified then the `list` command is assumed by default. Here are the list of commands: - `add` or `a`: add a new habit +- `commit`: commit to having done a habit +- `delete` or `del`: delete a habit +- `info` or `i`: get information about a habit - `help` or `h`: show help information - `list` or `ls`: list the habits available for today - `modify` or `mod`: modify the settings for a habit -- `delete` or `del`: delete a habit - `statistics` or `stats`: show statistics on current habits ## License diff --git a/src/habitmgr.rs b/src/habitmgr.rs index 54bae8d..6afd79f 100644 --- a/src/habitmgr.rs +++ b/src/habitmgr.rs @@ -108,9 +108,20 @@ impl HabitMgr println!("Removed habit {}", old_habit.get_name()); } + pub fn habit_info(&mut self, id:usize) + { + self.import_habits(); + let habit = &self.habits[id]; + println!("Name: {}", habit.get_name()); + println!("ID: {}", id); + println!("UID: {}", habit.get_uid()); + println!("Bad: {}", habit.get_bad()); + println!("Weight: {}", habit.get_weight()); + } + pub fn modify(&mut self, id:usize, name:Option, - bad:Option, + toggle_bad:bool, weight:Option, _days:Option) { @@ -119,9 +130,10 @@ impl HabitMgr { self.habits[id].set_name(name.unwrap()); } - if bad.is_some() + if toggle_bad { - self.habits[id].set_bad(bad.unwrap()); + let is_bad = self.habits[id].get_bad(); + self.habits[id].set_bad(!is_bad); } if weight.is_some() { diff --git a/src/main.rs b/src/main.rs index 0ec30a9..c6b0857 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,6 +52,15 @@ enum Command weight:u8, }, Commit { }, + #[structopt(alias = "del")] + Delete { + #[structopt(help = "ID of the habit to delete")] + id:usize, + }, + #[structopt(alias = "i")] + Info { + id:usize, + }, #[structopt(alias = "ls")] List { @@ -61,11 +70,17 @@ enum Command verbose:bool, }, #[structopt(alias = "mod")] - Modify { }, - #[structopt(alias = "del")] - Delete { - #[structopt(help = "ID of the habit to delete")] + Modify { + #[structopt(help = "ID of the habit to modify")] id:usize, + #[structopt(short, long)] + name:Option, + #[structopt(short, long)] + weight:Option, + #[structopt(long, short)] + days:Option, + #[structopt(long)] + toggle_bad:bool, }, #[structopt(alias = "stats")] Statistics { }, @@ -103,10 +118,14 @@ fn main() { Command::Add { name, days, bad, weight } => hmgr.add(name, bad, weight, days), - Command::List { all, verbose } => - hmgr.list(all, verbose), Command::Delete { id } => hmgr.delete(id), + Command::Info { id } => + hmgr.habit_info(id), + Command::List { all, verbose } => + hmgr.list(all, verbose), + Command::Modify { id, name, weight, days, toggle_bad } => + hmgr.modify(id, name, toggle_bad, weight, days), _ => todo!(), }, }