diff --git a/Cargo.lock b/Cargo.lock index 727655b..88ca21a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -417,6 +417,7 @@ dependencies = [ "clap", "directories", "elefren", + "env_logger", "html2md", "html5ever 0.25.1", "log", @@ -475,6 +476,19 @@ dependencies = [ "cfg-if 0.1.10", ] +[[package]] +name = "env_logger" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "error-chain" version = "0.12.1" @@ -712,6 +726,12 @@ version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.12.35" @@ -1959,6 +1979,15 @@ dependencies = [ "utf-8", ] +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + [[package]] name = "textwrap" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index 96d703b..d00b6ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ chrono = "0.4" clap = "2.33" directories = "3.0" elefren = { version = "0.20", features = ["toml"] } -# env_logger = "0.8" +env_logger = "0.8" html2md = "0.2" html5ever = "0.25" log = "0.4" diff --git a/src/args/mod.rs b/src/args/mod.rs index 3b48699..cf9b2b9 100644 --- a/src/args/mod.rs +++ b/src/args/mod.rs @@ -23,12 +23,14 @@ use std::convert::TryFrom; use clap::App; use clap::Arg; use clap::SubCommand; +use log_derive::logfn; use self::errors::ParsingError; use super::commands::Command; use super::commands::StorageType; /// Parse the command line, returning the necessary command. +#[logfn(Trace)] pub fn parse() -> Result { let parser = App::new(clap::crate_name!()) .version(clap::crate_version!()) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index d125d23..e04e822 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -35,6 +35,7 @@ use crate::storage::markdown::config::MarkdownConfig; type CommandResult = Result<(), CommandError>; /// Available Storages +#[derive(Debug)] pub enum StorageType { /// Store in the filesystem, as Markdown Markdown, @@ -60,6 +61,7 @@ impl TryFrom<&str> for StorageType { } /// Available commands +#[derive(Debug)] pub enum Command { /// Add a new account AddAccount(String), diff --git a/src/config/config.rs b/src/config/config.rs index 165afa8..e289562 100644 --- a/src/config/config.rs +++ b/src/config/config.rs @@ -23,6 +23,8 @@ use std::path::PathBuf; use directories::ProjectDirs; use elefren::Data; +use log_derive::logfn; +use log_derive::logfn_inputs; use serde_derive::Deserialize; use serde_derive::Serialize; @@ -36,6 +38,7 @@ pub struct Config(HashMap); impl Config { /// Figure out the filename for the configuration file. + #[logfn(Trace)] fn filename() -> Result { match ProjectDirs::from("me", "JulioBiason", "downfav.toml") { Some(proj_dirs) => Ok(proj_dirs.config_dir().into()), @@ -59,17 +62,20 @@ impl Config { } /// Add a new account to the configuration file + #[logfn_inputs(Trace)] pub fn add_account(&mut self, name: &str, configuration: Data) { let account_data = AccountConfig::new(configuration); self.0.insert(name.into(), account_data); } /// Remove account + #[logfn_inputs(Trace)] pub fn remove_account(&mut self, name: &str) { self.0.remove(name); } /// Set the configuration for the markdown storage + #[logfn_inputs(Trace)] pub fn set_storage_markdown( &mut self, account: &str, diff --git a/src/main.rs b/src/main.rs index 36a2dc3..d5e74eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,8 @@ mod config; mod storage; fn main() { + env_logger::init(); + match args::parse() { Ok(command) => command.execute().unwrap(), Err(e) => println!("Error: {:?}", e),