Complete add functionality.
This commit is contained in:
		@@ -39,7 +39,7 @@ impl HabitMgr
 | 
			
		||||
			File::create(&habits_path)
 | 
			
		||||
				.unwrap_or_else(|e| {
 | 
			
		||||
					panic!("Error creating file {}:\n{}",
 | 
			
		||||
								 habits_path.display(), e)
 | 
			
		||||
								 habits_path.display(), e);
 | 
			
		||||
				});
 | 
			
		||||
		}
 | 
			
		||||
		Self
 | 
			
		||||
@@ -78,6 +78,11 @@ impl HabitMgr
 | 
			
		||||
			});
 | 
			
		||||
 | 
			
		||||
		let habit = Habit::new(name, bad, weight);
 | 
			
		||||
		serde_json::to_writer(habits_file, &habit)
 | 
			
		||||
			.unwrap_or_else(|e| {
 | 
			
		||||
				panic!("Error writing to file {}:\n{}",
 | 
			
		||||
							 self.habits_path.display(), e);
 | 
			
		||||
			})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pub fn list(&mut self, all:bool, verbose:bool)
 | 
			
		||||
 
 | 
			
		||||
@@ -75,7 +75,7 @@ fn main()
 | 
			
		||||
	let data_dir =
 | 
			
		||||
		PathBuf::from(
 | 
			
		||||
			env::var("XDG_DATA_HOME")
 | 
			
		||||
			.unwrap_or_else(|e| { panic!("Error: {}", e) }))
 | 
			
		||||
			.unwrap_or_else(|e| { panic!("Error: {}", e); }))
 | 
			
		||||
		.join("htracker");
 | 
			
		||||
 | 
			
		||||
	if data_dir.exists() && data_dir.is_file()
 | 
			
		||||
@@ -87,7 +87,7 @@ fn main()
 | 
			
		||||
	{
 | 
			
		||||
		println!("First run: files will be stored in {}", data_dir.display());
 | 
			
		||||
		fs::create_dir_all(&data_dir)
 | 
			
		||||
			.unwrap_or_else(|e| { panic!("Filesystem error: {}", e) });
 | 
			
		||||
			.unwrap_or_else(|e| { panic!("Filesystem error: {}", e); });
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	let mut hmgr = HabitMgr::new(&data_dir);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user