Add modify and info features.

This commit is contained in:
Nicolás A. Ortega Froysa 2022-07-19 15:06:21 +02:00
parent ac3b111053
commit b5bd60ad40
3 changed files with 43 additions and 10 deletions

View File

@ -12,10 +12,12 @@ is specified then the `list` command is assumed by default. Here are the list of
commands: commands:
- `add` or `a`: add a new habit - `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 - `help` or `h`: show help information
- `list` or `ls`: list the habits available for today - `list` or `ls`: list the habits available for today
- `modify` or `mod`: modify the settings for a habit - `modify` or `mod`: modify the settings for a habit
- `delete` or `del`: delete a habit
- `statistics` or `stats`: show statistics on current habits - `statistics` or `stats`: show statistics on current habits
## License ## License

View File

@ -108,9 +108,20 @@ impl HabitMgr
println!("Removed habit {}", old_habit.get_name()); 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, pub fn modify(&mut self, id:usize,
name:Option<String>, name:Option<String>,
bad:Option<bool>, toggle_bad:bool,
weight:Option<u8>, weight:Option<u8>,
_days:Option<String>) _days:Option<String>)
{ {
@ -119,9 +130,10 @@ impl HabitMgr
{ {
self.habits[id].set_name(name.unwrap()); 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() if weight.is_some()
{ {

View File

@ -52,6 +52,15 @@ enum Command
weight:u8, weight:u8,
}, },
Commit { }, Commit { },
#[structopt(alias = "del")]
Delete {
#[structopt(help = "ID of the habit to delete")]
id:usize,
},
#[structopt(alias = "i")]
Info {
id:usize,
},
#[structopt(alias = "ls")] #[structopt(alias = "ls")]
List List
{ {
@ -61,11 +70,17 @@ enum Command
verbose:bool, verbose:bool,
}, },
#[structopt(alias = "mod")] #[structopt(alias = "mod")]
Modify { }, Modify {
#[structopt(alias = "del")] #[structopt(help = "ID of the habit to modify")]
Delete {
#[structopt(help = "ID of the habit to delete")]
id:usize, id:usize,
#[structopt(short, long)]
name:Option<String>,
#[structopt(short, long)]
weight:Option<u8>,
#[structopt(long, short)]
days:Option<String>,
#[structopt(long)]
toggle_bad:bool,
}, },
#[structopt(alias = "stats")] #[structopt(alias = "stats")]
Statistics { }, Statistics { },
@ -103,10 +118,14 @@ fn main()
{ {
Command::Add { name, days, bad, weight } => Command::Add { name, days, bad, weight } =>
hmgr.add(name, bad, weight, days), hmgr.add(name, bad, weight, days),
Command::List { all, verbose } =>
hmgr.list(all, verbose),
Command::Delete { id } => Command::Delete { id } =>
hmgr.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!(), _ => todo!(),
}, },
} }