diff --git a/Cargo.lock b/Cargo.lock index 42ae863..0cd8c64 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,6 +43,15 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi", +] + [[package]] name = "arrayref" version = "0.3.6" @@ -61,6 +70,17 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.0.1" @@ -232,6 +252,21 @@ dependencies = [ "libloading", ] +[[package]] +name = "clap" +version = "2.33.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +dependencies = [ + "ansi_term", + "atty", + "bitflags 1.2.1", + "strsim 0.8.0", + "textwrap", + "unicode-width", + "vec_map", +] + [[package]] name = "claxon" version = "0.4.3" @@ -350,9 +385,9 @@ dependencies = [ [[package]] name = "crossterm" -version = "0.18.2" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e86d73f2a0b407b5768d10a8c720cf5d2df49a9efc10ca09176d201ead4b7fb" +checksum = "7c36c10130df424b2f3552fcc2ddcd9b28a27b1e54b358b45874f88d1ca6888c" dependencies = [ "bitflags 1.2.1", "crossterm_winapi", @@ -366,9 +401,9 @@ dependencies = [ [[package]] name = "crossterm_winapi" -version = "0.6.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2265c3f8e080075d9b6417aa72293fc71662f34b4af2612d8d1b074d29510db" +checksum = "0da8964ace4d3e4a044fd027919b2237000b24315a37c916f61809f1ff2140b9" dependencies = [ "winapi", ] @@ -393,7 +428,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote 1.0.7", - "strsim", + "strsim 0.9.3", "syn 1.0.48", ] @@ -464,6 +499,7 @@ dependencies = [ name = "domasi" version = "0.1.0" dependencies = [ + "clap", "crossterm", "directories", "notify-rust", @@ -548,6 +584,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "hermit-abi" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +dependencies = [ + "libc", +] + [[package]] name = "hound" version = "3.4.0" @@ -1317,6 +1362,12 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef5430c8e36b713e13b48a9f709cc21e046723fe44ce34587b73a830203b533e" +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + [[package]] name = "strsim" version = "0.9.3" @@ -1388,6 +1439,15 @@ dependencies = [ "xattr", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "thiserror" version = "1.0.21" @@ -1467,6 +1527,12 @@ dependencies = [ "tinyvec 1.1.0", ] +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + [[package]] name = "unicode-xid" version = "0.0.4" @@ -1534,6 +1600,12 @@ dependencies = [ "percent-encoding 2.1.0", ] +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "version_check" version = "0.9.2" diff --git a/Cargo.toml b/Cargo.toml index 9d780c2..fe45ed6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,8 @@ version = "0.1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -notify-rust = "4.0" -rodio = "0.13" -directories = "3.0" -crossterm = "0.18" +notify-rust = "^4.0" +rodio = "^0.13" +directories = "^3.0" +crossterm = "^0.19" +clap = "^2.33" diff --git a/src/main.rs b/src/main.rs index 9cd2e58..270a6c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use clap::{App, Arg, SubCommand}; use directories::ProjectDirs; use domasi::Alert; use domasi::Domasi; @@ -5,35 +6,51 @@ use std::fs; use std::path::PathBuf; fn main() { - let mut args = std::env::args_os(); + let app = App::new("Domasi") + .version("0.1.0") + .author("Rekai Musuka ") + .about("CLI Pomodoro Timer") + .arg( + Arg::with_name("create-alert-dir") + .short("C") + .long("create-alert-dir") + .help("Creates the alert directory"), + ) + .subcommand(SubCommand::with_name("start").about("Start Pomodoro Timer")); + let matches = app.get_matches(); - if let Some(os_string) = args.nth(1) { - match os_string.to_str() { - Some("-C") | Some("--create-config") => { - let _ = create_alert_directory(); - } - None => {} - arg => println!("Unsupported Argument: {}", arg.unwrap()), + if matches.is_present("create-alert-dir") { + // Create the Alert Directory + match create_alert_directory() { + Ok(path) => println!("Created {:?}", path), + Err(err) => eprintln!("Failed to create Alert Dir: {}", err), } + + return; // Exit main } - let mut domasi: Domasi = Default::default(); + match matches.subcommand() { + ("start", Some(_sub_match)) => { + let mut domasi: Domasi = Default::default(); - match get_alert() { - Some(alert) => domasi.start(Some(alert)).unwrap(), - None => domasi.start(None).unwrap(), + match get_alert() { + Some(alert) => domasi.start(Some(alert)).unwrap(), + None => domasi.start(None).unwrap(), + } + } + _ => println!("No argument or subcommand provided."), } } -fn create_alert_directory() -> std::io::Result<()> { +fn create_alert_directory() -> std::io::Result { let alert_dir = ProjectDirs::from("moe", "paoda", "domasi") .unwrap() .data_dir() .to_path_buf() .join("alert"); - fs::create_dir_all(alert_dir)?; - Ok(()) + fs::create_dir_all(&alert_dir)?; + Ok(alert_dir) } fn get_alert() -> Option {