Add modify and info features.
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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<String>,
 | 
			
		||||
						 bad:Option<bool>,
 | 
			
		||||
						 toggle_bad:bool,
 | 
			
		||||
						 weight:Option<u8>,
 | 
			
		||||
						 _days:Option<String>)
 | 
			
		||||
	{
 | 
			
		||||
@@ -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()
 | 
			
		||||
		{
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										31
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								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<String>,
 | 
			
		||||
		#[structopt(short, long)]
 | 
			
		||||
		weight:Option<u8>,
 | 
			
		||||
		#[structopt(long, short)]
 | 
			
		||||
		days:Option<String>,
 | 
			
		||||
		#[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!(),
 | 
			
		||||
			},
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user