From 16e3f7361661755868fb274d9ecf0bb43da81c96 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 22 May 2020 00:21:27 -0500 Subject: [PATCH] Add --alert flag to start subcommand --- src/main.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7117c63..697c3f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,10 @@ use async_std::task; -use clap::{App, ArgMatches, SubCommand}; +use clap::{App, Arg, ArgMatches, SubCommand}; use crossterm::{cursor, terminal::Clear, terminal::ClearType, QueueableCommand}; use domasi::pomodoro::{Alert, Clock, Config, Status}; use domasi::Pomodoro; use std::io::{stdout, Write}; +use std::path::{Path, PathBuf}; use std::sync::mpsc::{channel, Receiver, Sender}; use std::thread; @@ -13,7 +14,18 @@ fn main() { .version("0.1.0") .author("paoda ") .about("Yet another pomodoro timer.") - .subcommand(SubCommand::with_name("start").about("Start the Pomodoro Timer")) + .subcommand( + SubCommand::with_name("start") + .about("Start the Pomodoro Timer") + .arg( + Arg::with_name("alert") + .short("a") + .long("alert") + .value_name("FILE") + .takes_value(true) + .help("Aloud Sound. (Supports WAV, MP3, Vorbis, FLAC)"), + ), + ) .get_matches(); // match matches.subcommand() { @@ -26,10 +38,16 @@ fn main() { } } -pub fn start(_args: &ArgMatches) { +pub fn start(args: &ArgMatches) { let config = Config::default(); - let audio_path = config.data_directory.join("sound/alert.ogg"); + let audio_path: PathBuf; + if let Some(path) = args.value_of("alert") { + audio_path = Path::new(path).to_path_buf(); + } else { + audio_path = config.data_directory.join("sound/alert.ogg"); + } + let default_device = rodio::default_output_device().unwrap(); let alert = Alert::new(&audio_path, &default_device); let mut pomodoro = Pomodoro::new(&alert);