add cli arg parsing
This commit is contained in:
parent
b49625a973
commit
99cc67b2a9
1 changed files with 48 additions and 2 deletions
50
src/main.rs
50
src/main.rs
|
@ -1,5 +1,40 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use clap::Parser;
|
||||
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() {
|
||||
let options = eframe::NativeOptions {
|
||||
|
@ -8,9 +43,20 @@ fn main() {
|
|||
..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(
|
||||
"katabastird",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(Timer::default())),
|
||||
Box::new(move |_cc| Box::new(Timer::new(duration, direction, !cli.running))),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue