Initial commit.
This commit is contained in:
50
src/habit.rs
Normal file
50
src/habit.rs
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Ortega Froysa, Nicolás <nicolas@ortegas.org>
|
||||
* Author: Ortega Froysa, Nicolás <nicolas@ortegas.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
pub struct Habit
|
||||
{
|
||||
uid:Uuid,
|
||||
name:String,
|
||||
bad:bool,
|
||||
weight:u8,
|
||||
}
|
||||
|
||||
impl Habit
|
||||
{
|
||||
pub fn new(name:String, bad:bool, weight:u8) -> Self
|
||||
{
|
||||
Self
|
||||
{
|
||||
uid: Uuid::new_v4(),
|
||||
name,
|
||||
bad,
|
||||
weight,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_uid(&self) -> String { self.uid.to_string() }
|
||||
pub fn get_name(&self) -> &String { &self.name }
|
||||
pub fn get_bad(&self) -> bool { self.bad }
|
||||
pub fn get_weight(&self) -> u8 { self.weight }
|
||||
|
||||
pub fn set_name(&mut self, name:String) { self.name = name; }
|
||||
pub fn set_bad(&mut self, bad:bool) { self.bad = bad; }
|
||||
pub fn set_weight(&mut self, weight:u8) { self.weight = weight; }
|
||||
}
|
48
src/habitmgr.rs
Normal file
48
src/habitmgr.rs
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Ortega Froysa, Nicolás <nicolas@ortegas.org>
|
||||
* Author: Ortega Froysa, Nicolás <nicolas@ortegas.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use crate::habit::Habit;
|
||||
|
||||
pub struct HabitMgr
|
||||
{
|
||||
habits:Vec<Habit>,
|
||||
}
|
||||
|
||||
impl HabitMgr
|
||||
{
|
||||
pub fn new() -> Self
|
||||
{
|
||||
Self
|
||||
{
|
||||
habits: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add(&mut self, name:String, bad:bool, weight:u8, _days:String)
|
||||
{
|
||||
self.habits.push(Habit::new(name, bad, weight));
|
||||
}
|
||||
|
||||
pub fn list(&self, all:bool, verbose:bool)
|
||||
{
|
||||
for i in &self.habits
|
||||
{
|
||||
println!("{}", i.get_name());
|
||||
}
|
||||
}
|
||||
}
|
86
src/main.rs
Normal file
86
src/main.rs
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Ortega Froysa, Nicolás <nicolas@ortegas.org>
|
||||
* Author: Ortega Froysa, Nicolás <nicolas@ortegas.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use structopt::StructOpt;
|
||||
use structopt::clap::AppSettings;
|
||||
|
||||
mod habit;
|
||||
mod habitmgr;
|
||||
use habitmgr::HabitMgr;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
#[structopt(
|
||||
setting = AppSettings::InferSubcommands,
|
||||
about = "A CLI tool to help form good habits and lose bad ones.")]
|
||||
struct Opts
|
||||
{
|
||||
#[structopt(subcommand)]
|
||||
cmd:Option<Command>,
|
||||
}
|
||||
|
||||
#[derive(StructOpt)]
|
||||
enum Command
|
||||
{
|
||||
#[structopt(alias = "a")]
|
||||
Add
|
||||
{
|
||||
#[structopt(help = "name of the new habit")]
|
||||
name:String,
|
||||
#[structopt(long, short, default_value = "mon,tue,wed,thu,fri,sat,sun")]
|
||||
days:String,
|
||||
#[structopt(long)]
|
||||
bad:bool,
|
||||
#[structopt(short, long, default_value = "5")]
|
||||
weight:u8,
|
||||
},
|
||||
Commit { },
|
||||
#[structopt(alias = "ls")]
|
||||
List
|
||||
{
|
||||
#[structopt(short, long, help = "list all active habits")]
|
||||
all:bool,
|
||||
#[structopt(short, long, help = "show UUIDs")]
|
||||
verbose:bool,
|
||||
},
|
||||
#[structopt(alias = "mod")]
|
||||
Modify { },
|
||||
#[structopt(alias = "rm")]
|
||||
Remove { },
|
||||
#[structopt(alias = "stats")]
|
||||
Statistics { },
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
let opts = Opts::from_args();
|
||||
let mut hmgr = HabitMgr::new();
|
||||
|
||||
match opts.cmd
|
||||
{
|
||||
None => hmgr.list(false, false),
|
||||
Some(c) =>
|
||||
match c
|
||||
{
|
||||
Command::Add { name, days, bad, weight } =>
|
||||
hmgr.add(name, bad, weight, days),
|
||||
Command::List { all, verbose } =>
|
||||
hmgr.list(all, verbose),
|
||||
_ => todo!(),
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user