add cli arg parsing

This commit is contained in:
Joe Ardent 2022-10-13 18:06:08 -07:00
parent b49625a973
commit 99cc67b2a9

View file

@ -1,5 +1,40 @@
use std::time::Duration;
use clap::Parser;
use egui::Vec2; use egui::Vec2;
use katabastird::timer::Timer; use katabastird::timer::{CountDirection, Timer};
#[derive(Debug, Parser)]
#[clap(author, version, about)]
struct Cli {
/// Hours to count down.
#[clap(long, default_value_t = 0)]
hours: u64,
/// Minutes to count down.
#[clap(long, short, default_value_t = 0)]
minutes: u64,
/// Seconds to count down.
#[clap(long, short, default_value_t = 0)]
seconds: u64,
/// Audio file to play at the end of the countdown.
#[clap(long, short)]
alarm: Option<String>,
/// Begin countdown immediately.
#[clap(long = "immediate", long = "running", short = 'i', short = 'r')]
running: bool,
/// Count up from zero, actually.
#[clap(long, short = 'u')]
count_up: bool,
/// Use the Predator font.
#[clap(long, short)]
predator: bool,
}
fn main() { fn main() {
let options = eframe::NativeOptions { let options = eframe::NativeOptions {
@ -8,9 +43,20 @@ fn main() {
..Default::default() ..Default::default()
}; };
let cli = Cli::parse();
let seconds = cli.hours * 3600 + cli.minutes * 60 + cli.seconds;
let duration = Duration::from_secs(seconds.max(30));
let direction = if cli.count_up {
CountDirection::Up
} else {
CountDirection::Down
};
eframe::run_native( eframe::run_native(
"katabastird", "katabastird",
options, options,
Box::new(|_cc| Box::new(Timer::default())), Box::new(move |_cc| Box::new(Timer::new(duration, direction, !cli.running))),
); );
} }