Add --create-config flag to cli

This commit is contained in:
Rekai Musuka 2020-06-29 18:11:26 -05:00
parent f79fde6d16
commit 40c682515f
4 changed files with 120 additions and 110 deletions

122
Cargo.lock generated
View File

@ -16,7 +16,7 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [ dependencies = [
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -80,7 +80,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [ dependencies = [
"hermit-abi", "hermit-abi",
"libc", "libc",
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -177,9 +177,9 @@ checksum = "24508e28c677875c380c20f4d28124fab6f8ed4ef929a1397d7b1a31e92f1005"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.54" version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7bbb73db36c1246e9034e307d0fba23f9a2e251faa47ade70c1bd252220c8311" checksum = "77c1f1d60091c1b73e2b1f4560ab419204b178e625fa945ded7b660becd2bd46"
[[package]] [[package]]
name = "cexpr" name = "cexpr"
@ -281,9 +281,9 @@ dependencies = [
[[package]] [[package]]
name = "coreaudio-sys" name = "coreaudio-sys"
version = "0.2.4" version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e81f1c165c33ffab90a03077ac3b03462b34d5947145dfa48102e063d581502c" checksum = "d6570ee6e089131e928d5ec9236db9e818aa3cf850f48b0eec6ef700571271d4"
dependencies = [ dependencies = [
"bindgen", "bindgen",
] ]
@ -302,7 +302,7 @@ dependencies = [
"num-traits", "num-traits",
"stdweb", "stdweb",
"thiserror", "thiserror",
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -329,7 +329,7 @@ dependencies = [
"mio", "mio",
"parking_lot", "parking_lot",
"signal-hook", "signal-hook",
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -338,7 +338,7 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "057b7146d02fb50175fd7dbe5158f6097f33d02831f43b4ee8ae4ddf67b68f5c" checksum = "057b7146d02fb50175fd7dbe5158f6097f33d02831f43b4ee8ae4ddf67b68f5c"
dependencies = [ dependencies = [
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -369,7 +369,7 @@ checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901"
dependencies = [ dependencies = [
"libc", "libc",
"redox_users", "redox_users",
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -380,7 +380,7 @@ checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a"
dependencies = [ dependencies = [
"libc", "libc",
"redox_users", "redox_users",
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -401,9 +401,9 @@ dependencies = [
[[package]] [[package]]
name = "fastrand" name = "fastrand"
version = "1.2.4" version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a64b0126b293b050395b37b10489951590ed024c03d7df4f249d219c8ded7cbf" checksum = "b90eb1dec02087df472ab9f0db65f27edaa654a746830042688bcc2eaf68090f"
[[package]] [[package]]
name = "fuchsia-zircon" name = "fuchsia-zircon"
@ -517,9 +517,9 @@ dependencies = [
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.40" version = "0.3.41"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce10c23ad2ea25ceca0093bd3192229da4c5b3c0f2de499c1ecac0d98d452177" checksum = "c4b9172132a62451e56142bff9afc91c8e4a4500aa5b847da36815b63bfda916"
dependencies = [ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
@ -588,7 +588,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753"
dependencies = [ dependencies = [
"cc", "cc",
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -703,7 +703,7 @@ checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -802,9 +802,9 @@ checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d"
[[package]] [[package]]
name = "parking" name = "parking"
version = "1.0.1" version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a7fad362df89617628a7508b3e9d588ade1b0ac31aa25de168193ad999c2dd4" checksum = "c4029bc3504a62d92e42f30b9095fdef73b8a0b2a06aa41ce2935143b05a1a06"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
@ -827,7 +827,7 @@ dependencies = [
"libc", "libc",
"redox_syscall", "redox_syscall",
"smallvec", "smallvec",
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -853,7 +853,7 @@ checksum = "6a0ffd45cf79d88737d7cc85bfd5d2894bee1139b356e616fe85dc389c61aaf7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote 1.0.7", "quote 1.0.7",
"syn 1.0.32", "syn 1.0.33",
] ]
[[package]] [[package]]
@ -880,7 +880,7 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
dependencies = [ dependencies = [
"unicode-xid 0.2.0", "unicode-xid 0.2.1",
] ]
[[package]] [[package]]
@ -976,22 +976,22 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.113" version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6135c78461981c79497158ef777264c51d9d0f4f3fc3a4d22b915900e42dac6a" checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.113" version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93c5eaa17d0954cb481cdcfffe9d84fcfa7a1a9f2349271e678677be4c26ae31" checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote 1.0.7", "quote 1.0.7",
"syn 1.0.32", "syn 1.0.33",
] ]
[[package]] [[package]]
@ -1035,7 +1035,7 @@ checksum = "31ef6ee280cdefba6d2d0b4b78a84a1c1a3f3a4cec98c2d4231c8bc225de0f25"
dependencies = [ dependencies = [
"libc", "libc",
"mach", "mach",
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -1062,7 +1062,7 @@ dependencies = [
"slab", "slab",
"socket2", "socket2",
"wepoll-sys-stjepang", "wepoll-sys-stjepang",
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -1074,7 +1074,7 @@ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"redox_syscall", "redox_syscall",
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -1118,13 +1118,13 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.32" version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a994520748611c17d163e81b6c4a4b13d11b7f63884362ab2efac3aa9cf16d00" checksum = "e8d5d96e8cbb005d6959f119f773bfaebb5684296108fb32600c00cde305b2cd"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote 1.0.7", "quote 1.0.7",
"unicode-xid 0.2.0", "unicode-xid 0.2.1",
] ]
[[package]] [[package]]
@ -1162,7 +1162,7 @@ checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote 1.0.7", "quote 1.0.7",
"syn 1.0.32", "syn 1.0.33",
] ]
[[package]] [[package]]
@ -1172,7 +1172,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
dependencies = [ dependencies = [
"libc", "libc",
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -1192,9 +1192,9 @@ dependencies = [
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
version = "0.1.7" version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
@ -1204,9 +1204,9 @@ checksum = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.0" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]] [[package]]
name = "vec_map" name = "vec_map"
@ -1234,9 +1234,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.63" version = "0.2.64"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c2dc4aa152834bc334f506c1a06b866416a8b6697d5c9f75b9a689c8486def0" checksum = "6a634620115e4a229108b71bde263bb4220c483b3f07f5ba514ee8d15064c4c2"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"wasm-bindgen-macro", "wasm-bindgen-macro",
@ -1244,24 +1244,24 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.63" version = "0.2.64"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ded84f06e0ed21499f6184df0e0cb3494727b0c5da89534e0fcc55c51d812101" checksum = "3e53963b583d18a5aa3aaae4b4c1cb535218246131ba22a71f05b518098571df"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"lazy_static", "lazy_static",
"log", "log",
"proc-macro2", "proc-macro2",
"quote 1.0.7", "quote 1.0.7",
"syn 1.0.32", "syn 1.0.33",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "wasm-bindgen-futures" name = "wasm-bindgen-futures"
version = "0.4.13" version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64487204d863f109eb77e8462189d111f27cb5712cc9fdb3461297a76963a2f6" checksum = "dba48d66049d2a6cc8488702e7259ab7afc9043ad0dc5448444f46f2a453b362"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
@ -1271,9 +1271,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.63" version = "0.2.64"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "838e423688dac18d73e31edce74ddfac468e37b1506ad163ffaf0a46f703ffe3" checksum = "3fcfd5ef6eec85623b4c6e844293d4516470d8f19cd72d0d12246017eb9060b8"
dependencies = [ dependencies = [
"quote 1.0.7", "quote 1.0.7",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@ -1281,28 +1281,28 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.63" version = "0.2.64"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3156052d8ec77142051a533cdd686cba889537b213f948cd1d20869926e68e92" checksum = "9adff9ee0e94b926ca81b57f57f86d5545cdcb1d259e21ec9bdd95b901754c75"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote 1.0.7", "quote 1.0.7",
"syn 1.0.32", "syn 1.0.33",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.63" version = "0.2.64"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9ba19973a58daf4db6f352eda73dc0e289493cd29fb2632eb172085b6521acd" checksum = "7f7b90ea6c632dd06fd765d44542e234d5e63d9bb917ecd64d79778a13bd79ae"
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.40" version = "0.3.41"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b72fe77fd39e4bd3eaa4412fd299a0be6b3dfe9d2597e2f1c20beb968f41d17" checksum = "863539788676619aac1a23e2df3655e96b32b0e05eb72ca34ba045ad573c625d"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@ -1310,9 +1310,9 @@ dependencies = [
[[package]] [[package]]
name = "wepoll-sys-stjepang" name = "wepoll-sys-stjepang"
version = "1.0.0" version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74e0414ddefc9d668689fa1540beede94710b2b978bb531335051a0172a4f496" checksum = "6fd319e971980166b53e17b1026812ad66c6b54063be879eb182342b55284694"
dependencies = [ dependencies = [
"cc", "cc",
] ]
@ -1325,9 +1325,9 @@ checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.8" version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [ dependencies = [
"winapi-i686-pc-windows-gnu", "winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu",
@ -1357,7 +1357,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e30cba82e22b083dc5a422c2ee77e20dc7927271a0dc981360c57c1453cb48d" checksum = "7e30cba82e22b083dc5a422c2ee77e20dc7927271a0dc981360c57c1453cb48d"
dependencies = [ dependencies = [
"winapi 0.3.8", "winapi 0.3.9",
] ]
[[package]] [[package]]
@ -1368,7 +1368,7 @@ checksum = "6c31a65da50d792c6f9bd2e3216249566c4fb1d2d34f9b7d2d66d2e93f62a242"
dependencies = [ dependencies = [
"strum", "strum",
"strum_macros", "strum_macros",
"winapi 0.3.8", "winapi 0.3.9",
"winrt", "winrt",
"xml-rs", "xml-rs",
] ]

View File

@ -1,23 +1,23 @@
[package] [package]
name = "domasi"
version = "0.1.0"
authors = ["Rekai Musuka <musukarekai@gmail.com>"] authors = ["Rekai Musuka <musukarekai@gmail.com>"]
edition = "2018" edition = "2018"
name = "domasi"
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]
rodio = "0.11.0" anyhow = "1.0.31"
clap = "2.33.1" async-std = "1.6.2"
clap = "2.33.1"
crossterm = "0.17.5"
directories = "3.0.0" directories = "3.0.0"
async-std = "1.6.2" rodio = "0.11.0"
crossterm = "0.17.5" serde = { version = "1.0.114", features = ["derive"] }
anyhow = "1.0.31" toml = "0.5.6"
toml = "0.5.6"
serde = { version = "1.0.113", features = ["derive"] }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
# winrt = { git = "https://github.com/microsoft/winrt-rs" } # winrt = "0.7.0"
winrt-notification = "0.2.2" winrt-notification = "0.2.2"
[target.'cfg(any(target_os = "macos", target_os = "linux"))'.dependencies] [target.'cfg(any(target_os = "macos", target_os = "linux"))'.dependencies]

View File

@ -1,7 +1,7 @@
use anyhow::Result; use anyhow::Result;
use directories::ProjectDirs; use directories::ProjectDirs;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fs::{self, File}; use std::fs::File;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::time::Duration; use std::time::Duration;
@ -18,8 +18,6 @@ pub struct Config {
impl Config { impl Config {
pub fn new(work: u64, short_break: u64, long_break: u64) -> Self { pub fn new(work: u64, short_break: u64, long_break: u64) -> Self {
Self::init_directories();
Config { Config {
work_time: Duration::from_secs(work), work_time: Duration::from_secs(work),
short_break: Duration::from_secs(short_break), short_break: Duration::from_secs(short_break),
@ -28,26 +26,8 @@ impl Config {
} }
} }
fn init_directories() {
let config_dir = Self::get_config_directory();
let data_dir = Self::get_data_directory();
if !config_dir.exists() {
let _ = fs::create_dir_all(config_dir);
}
if !data_dir.exists() {
let _ = fs::create_dir_all(data_dir);
}
}
pub fn save(config: &Config) -> Result<()> { pub fn save(config: &Config) -> Result<()> {
let config_directory = Self::get_config_directory(); let config_directory = Self::get_config_directory();
if !config_directory.exists() {
fs::create_dir_all(&config_directory)?;
}
Self::write_to_file(&config_directory.join(SETTINGS_FILE), config) Self::write_to_file(&config_directory.join(SETTINGS_FILE), config)
} }
@ -74,14 +54,14 @@ impl Config {
pub fn get_data_directory() -> PathBuf { pub fn get_data_directory() -> PathBuf {
ProjectDirs::from("moe", "paoda", "domasi") ProjectDirs::from("moe", "paoda", "domasi")
.unwrap() .unwrap()
.config_dir() .data_dir()
.to_path_buf() .to_path_buf()
} }
fn get_config_directory() -> PathBuf { fn get_config_directory() -> PathBuf {
ProjectDirs::from("moe", "paoda", "domasi") ProjectDirs::from("moe", "paoda", "domasi")
.unwrap() .unwrap()
.data_dir() .config_dir()
.to_path_buf() .to_path_buf()
} }
} }

View File

@ -19,6 +19,12 @@ fn main() {
.version("0.1.0") .version("0.1.0")
.author("paoda <musukarekai@gmail.com>") .author("paoda <musukarekai@gmail.com>")
.about("Yet another pomodoro timer.") .about("Yet another pomodoro timer.")
.arg(
Arg::with_name("create-config")
.short("C")
.long("create-config")
.help("Creates a Settings.toml and an alert directory"),
)
.subcommand( .subcommand(
SubCommand::with_name("start") SubCommand::with_name("start")
.about("Start the Pomodoro Timer") .about("Start the Pomodoro Timer")
@ -38,11 +44,48 @@ fn main() {
// _ => {} // _ => {}
// } // }
if matches.is_present("create-config") {
create_config()
}
if let ("start", Some(sub_matches)) = matches.subcommand() { if let ("start", Some(sub_matches)) = matches.subcommand() {
start(sub_matches); start(sub_matches);
} }
} }
pub fn create_config() {
let config_dir = Config::get_data_directory();
let data_dir = Config::get_data_directory().join("alert");
if !config_dir.exists() {
fs::create_dir_all(&config_dir).unwrap_or_else(|err| {
panic!("Failed to create {}: {}", config_dir.to_string_lossy(), err)
})
}
if !data_dir.exists() {
fs::create_dir_all(&data_dir).unwrap_or_else(|err| {
panic!("Failed to create {}: {}", data_dir.to_string_lossy(), err)
});
}
let config: Config = Default::default();
Config::save(&config).unwrap_or_else(|err| {
let cfg_path = config_dir.to_string_lossy();
panic!("Error while writing settings.toml to {}: {}", cfg_path, err);
});
let data_path = data_dir.to_string_lossy();
let settings_path = config_dir.join("settings.toml");
let settings_path = settings_path.to_string_lossy();
println!(
"Successfully created \"{}\" and \"{}\"",
settings_path, data_path
);
}
pub fn start(args: &ArgMatches) { pub fn start(args: &ArgMatches) {
let mut pomodoro = Pomodoro::new(); let mut pomodoro = Pomodoro::new();
@ -87,7 +130,7 @@ pub fn start(args: &ArgMatches) {
None => { None => {
// Look in the default locations // Look in the default locations
// check for .mp3, .wav, .ogg, .flac // check for .mp3, .wav, .ogg, .flac
let data_dir = Config::get_data_directory(); let data_dir = Config::get_data_directory().join("alert");
let data_dir_str = data_dir.to_string_lossy(); let data_dir_str = data_dir.to_string_lossy();
let items = fs::read_dir(&data_dir).unwrap_or_else(|_err| { let items = fs::read_dir(&data_dir).unwrap_or_else(|_err| {
@ -119,24 +162,11 @@ fn get_audio_file(items: std::fs::ReadDir) -> Option<PathBuf> {
match maybe_entry { match maybe_entry {
Ok(entry) => match entry.path().extension() { Ok(entry) => match entry.path().extension() {
Some(ext) => match ext.to_str() { Some(ext) => match ext.to_str() {
Some("mp3") => { Some("mp3") | Some("wav") | Some("ogg") | Some("flac") => {
result = Some(entry.path()); result = Some(entry.path());
break; break;
} }
Some("wav") => { _ => continue,
result = Some(entry.path());
break;
}
Some("ogg") => {
result = Some(entry.path());
break;
}
Some("flac") => {
result = Some(entry.path());
break;
}
Some(_ext) => continue,
None => continue,
}, },
None => continue, None => continue,
}, },