feat: parse cli commands with clap
This commit is contained in:
parent
500b1069bb
commit
c46b0bfb71
|
@ -43,6 +43,15 @@ dependencies = [
|
||||||
"pkg-config",
|
"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]]
|
[[package]]
|
||||||
name = "arrayref"
|
name = "arrayref"
|
||||||
version = "0.3.6"
|
version = "0.3.6"
|
||||||
|
@ -61,6 +70,17 @@ version = "0.9.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e"
|
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]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
|
@ -232,6 +252,21 @@ dependencies = [
|
||||||
"libloading",
|
"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]]
|
[[package]]
|
||||||
name = "claxon"
|
name = "claxon"
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
|
@ -350,9 +385,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossterm"
|
name = "crossterm"
|
||||||
version = "0.18.2"
|
version = "0.19.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4e86d73f2a0b407b5768d10a8c720cf5d2df49a9efc10ca09176d201ead4b7fb"
|
checksum = "7c36c10130df424b2f3552fcc2ddcd9b28a27b1e54b358b45874f88d1ca6888c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.2.1",
|
"bitflags 1.2.1",
|
||||||
"crossterm_winapi",
|
"crossterm_winapi",
|
||||||
|
@ -366,9 +401,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossterm_winapi"
|
name = "crossterm_winapi"
|
||||||
version = "0.6.2"
|
version = "0.7.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c2265c3f8e080075d9b6417aa72293fc71662f34b4af2612d8d1b074d29510db"
|
checksum = "0da8964ace4d3e4a044fd027919b2237000b24315a37c916f61809f1ff2140b9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
@ -393,7 +428,7 @@ dependencies = [
|
||||||
"ident_case",
|
"ident_case",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote 1.0.7",
|
"quote 1.0.7",
|
||||||
"strsim",
|
"strsim 0.9.3",
|
||||||
"syn 1.0.48",
|
"syn 1.0.48",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -464,6 +499,7 @@ dependencies = [
|
||||||
name = "domasi"
|
name = "domasi"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"clap",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"directories",
|
"directories",
|
||||||
"notify-rust",
|
"notify-rust",
|
||||||
|
@ -548,6 +584,15 @@ version = "0.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
|
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]]
|
[[package]]
|
||||||
name = "hound"
|
name = "hound"
|
||||||
version = "3.4.0"
|
version = "3.4.0"
|
||||||
|
@ -1317,6 +1362,12 @@ version = "0.1.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ef5430c8e36b713e13b48a9f709cc21e046723fe44ce34587b73a830203b533e"
|
checksum = "ef5430c8e36b713e13b48a9f709cc21e046723fe44ce34587b73a830203b533e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strsim"
|
name = "strsim"
|
||||||
version = "0.9.3"
|
version = "0.9.3"
|
||||||
|
@ -1388,6 +1439,15 @@ dependencies = [
|
||||||
"xattr",
|
"xattr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "textwrap"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.21"
|
version = "1.0.21"
|
||||||
|
@ -1467,6 +1527,12 @@ dependencies = [
|
||||||
"tinyvec 1.1.0",
|
"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]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-xid"
|
||||||
version = "0.0.4"
|
version = "0.0.4"
|
||||||
|
@ -1534,6 +1600,12 @@ dependencies = [
|
||||||
"percent-encoding 2.1.0",
|
"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]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.2"
|
version = "0.9.2"
|
||||||
|
|
|
@ -7,7 +7,8 @@ version = "0.1.0"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
notify-rust = "4.0"
|
notify-rust = "^4.0"
|
||||||
rodio = "0.13"
|
rodio = "^0.13"
|
||||||
directories = "3.0"
|
directories = "^3.0"
|
||||||
crossterm = "0.18"
|
crossterm = "^0.19"
|
||||||
|
clap = "^2.33"
|
||||||
|
|
47
src/main.rs
47
src/main.rs
|
@ -1,3 +1,4 @@
|
||||||
|
use clap::{App, Arg, SubCommand};
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use domasi::Alert;
|
use domasi::Alert;
|
||||||
use domasi::Domasi;
|
use domasi::Domasi;
|
||||||
|
@ -5,35 +6,51 @@ use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut args = std::env::args_os();
|
let app = App::new("Domasi")
|
||||||
|
.version("0.1.0")
|
||||||
|
.author("Rekai Musuka <rekai@musuka.dev>")
|
||||||
|
.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) {
|
if matches.is_present("create-alert-dir") {
|
||||||
match os_string.to_str() {
|
// Create the Alert Directory
|
||||||
Some("-C") | Some("--create-config") => {
|
match create_alert_directory() {
|
||||||
let _ = create_alert_directory();
|
Ok(path) => println!("Created {:?}", path),
|
||||||
}
|
Err(err) => eprintln!("Failed to create Alert Dir: {}", err),
|
||||||
None => {}
|
|
||||||
arg => println!("Unsupported Argument: {}", arg.unwrap()),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
match get_alert() {
|
||||||
Some(alert) => domasi.start(Some(alert)).unwrap(),
|
Some(alert) => domasi.start(Some(alert)).unwrap(),
|
||||||
None => domasi.start(None).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<PathBuf> {
|
||||||
let alert_dir = ProjectDirs::from("moe", "paoda", "domasi")
|
let alert_dir = ProjectDirs::from("moe", "paoda", "domasi")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.data_dir()
|
.data_dir()
|
||||||
.to_path_buf()
|
.to_path_buf()
|
||||||
.join("alert");
|
.join("alert");
|
||||||
|
|
||||||
fs::create_dir_all(alert_dir)?;
|
fs::create_dir_all(&alert_dir)?;
|
||||||
Ok(())
|
Ok(alert_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_alert() -> Option<Alert> {
|
fn get_alert() -> Option<Alert> {
|
||||||
|
|
Loading…
Reference in New Issue