From c9d6714eb6bbbaac417e2b3d488682450fe83599 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Mon, 11 May 2020 16:57:21 -0300 Subject: [PATCH] Removed dbg!s, used log --- Cargo.lock | 105 +++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 + README.md | 2 +- src/args/validators.rs | 7 ++- src/main.rs | 14 +++++- 5 files changed, 125 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 752a68d..4bcd05e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,14 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" +dependencies = [ + "memchr", +] + [[package]] name = "ansi_term" version = "0.11.0" @@ -64,6 +73,19 @@ dependencies = [ "vec_map", ] +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "getrandom" version = "0.1.14" @@ -84,12 +106,42 @@ dependencies = [ "libc", ] +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.67" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018" +[[package]] +name = "log" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + [[package]] name = "num-integer" version = "0.1.42" @@ -124,6 +176,12 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.3" @@ -180,6 +238,24 @@ version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +[[package]] +name = "regex" +version = "1.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" + [[package]] name = "serde" version = "1.0.104" @@ -214,6 +290,15 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "termcolor" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +dependencies = [ + "winapi-util", +] + [[package]] name = "textwrap" version = "0.11.0" @@ -223,6 +308,15 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "thread_local" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +dependencies = [ + "lazy_static", +] + [[package]] name = "time" version = "0.1.42" @@ -249,6 +343,8 @@ version = "0.1.0" dependencies = [ "chrono", "clap", + "env_logger", + "log", "serde", "serde_derive", "toml", @@ -304,6 +400,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 3cd3d9f..a5b834d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,5 @@ serde = "*" serde_derive = "*" toml = "0.5" uuid = { version = "0.8", features = ["v4"] } +log = "*" +env_logger = "0.7.1" diff --git a/README.md b/README.md index b2f9085..967dde6 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ tell you that you have 15 days up to it. - [ ] Sort events by ETA - [ ] Option to remove events - [ ] Move the app "db" to a fixed space -- [ ] Replace `dbg!` with [env_logger](https://crates.io/crates/env_logger) +- [x] Replace `dbg!` with [env_logger](https://crates.io/crates/env_logger) (reasoning: Although `dbg!` is nice and dandy, it can't be disabled, and that's bad UI) - [ ] Remove `unwrap()`s (for example, in the argument parsing). diff --git a/src/args/validators.rs b/src/args/validators.rs index 63cadd0..eb1dcb4 100644 --- a/src/args/validators.rs +++ b/src/args/validators.rs @@ -17,10 +17,12 @@ */ use chrono::prelude::*; +use log; pub fn date(input: String) -> Result<(), String> { let fake_datetime = format!("{} 00:00:00", input); - if let Ok(_) = dbg!(Utc.datetime_from_str(&fake_datetime, "%Y-%m-%d %H:%M:%S")) { + if let Ok(parse) = Utc.datetime_from_str(&fake_datetime, "%Y-%m-%d %H:%M:%S") { + log::debug!("Parsing {} ({})= {:?}", input, fake_datetime, parse); Ok(()) } else { Err(format!("Invalid date: '{}'", input)) @@ -29,7 +31,8 @@ pub fn date(input: String) -> Result<(), String> { pub fn time(input: String) -> Result<(), String> { let fake_datetime = format!("2020-01-01 {}:00", input); - if let Ok(_) = dbg!(Utc.datetime_from_str(&fake_datetime, "%Y-%m-%d %H:%M:%S")) { + if let Ok(parse) = Utc.datetime_from_str(&fake_datetime, "%Y-%m-%d %H:%M:%S") { + log::debug!("Parsing {} ({}) = {:?}", input, fake_datetime, parse); Ok(()) } else { Err(format!("Invalid time: '{}'", input)) diff --git a/src/main.rs b/src/main.rs index 55378d5..af0a929 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,8 @@ along with this program. If not, see . */ +use log; + mod args; mod eventlist; @@ -23,7 +25,10 @@ use crate::eventlist::event::Event; use crate::eventlist::eventlist::EventList; fn main() { - if let Ok(command) = dbg!(args::parse()) { + env_logger::init(); + + if let Ok(command) = args::parse() { + log::debug!("Command: {:?}", command); match command { args::Action::List => list(), args::Action::Add(description, date) => add_with_date(&description, &date), @@ -41,7 +46,12 @@ fn list() { fn add_with_date(description: &str, date: &str) { let event = Event::new_on_date(description, date); - let mut event_list = dbg!(EventList::load()); + println!("Adding event {}", event); + + let mut event_list = EventList::load(); + log::debug!("EventList: {:?}", event_list); event_list.push(event); event_list.save(); + + println!("Done."); }