fix: initial values via args
This commit is contained in:
parent
ca81094a36
commit
3ea715f83b
13
src/app.rs
13
src/app.rs
@ -82,11 +82,14 @@ impl From<(Args, AppStorage)> for AppArgs {
|
||||
style: args.style.unwrap_or(stg.style),
|
||||
pomodoro_mode: stg.pomodoro_mode,
|
||||
initial_value_work: args.work.unwrap_or(stg.inital_value_work),
|
||||
current_value_work: stg.current_value_work,
|
||||
initial_value_pause: args.pause,
|
||||
current_value_pause: stg.current_value_pause,
|
||||
initial_value_countdown: args.countdown,
|
||||
current_value_countdown: stg.current_value_countdown,
|
||||
// invalidate `current_value_work` if an initial value is set via args
|
||||
current_value_work: args.work.unwrap_or(stg.current_value_work),
|
||||
initial_value_pause: args.pause.unwrap_or(stg.inital_value_pause),
|
||||
// invalidate `current_value_pause` if an initial value is set via args
|
||||
current_value_pause: args.pause.unwrap_or(stg.current_value_pause),
|
||||
initial_value_countdown: args.countdown.unwrap_or(stg.inital_value_countdown),
|
||||
// invalidate `current_value_countdown` if an initial value is set via args
|
||||
current_value_countdown: args.countdown.unwrap_or(stg.current_value_countdown),
|
||||
current_value_timer: stg.current_value_timer,
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,10 +10,9 @@ use crate::{app::Content, widgets::clock::Style};
|
||||
#[derive(Parser)]
|
||||
pub struct Args {
|
||||
#[arg(long, short, value_parser = parse_duration,
|
||||
default_value="10:00" /* 10min */,
|
||||
help = "Countdown time to start from. Formats: 'ss', 'mm:ss', or 'hh:mm:ss'"
|
||||
)]
|
||||
pub countdown: Duration,
|
||||
pub countdown: Option<Duration>,
|
||||
|
||||
#[arg(long, short, value_parser = parse_duration,
|
||||
help = "Work time to count down from. Formats: 'ss', 'mm:ss', or 'hh:mm:ss'"
|
||||
@ -21,10 +20,9 @@ pub struct Args {
|
||||
pub work: Option<Duration>,
|
||||
|
||||
#[arg(long, short, value_parser = parse_duration,
|
||||
default_value="5:00" /* 5min */,
|
||||
help = "Pause time to count down from. Formats: 'ss', 'mm:ss', or 'hh:mm:ss'"
|
||||
)]
|
||||
pub pause: Duration,
|
||||
pub pause: Option<Duration>,
|
||||
|
||||
#[arg(long, short = 'd', help = "Whether to show deciseconds or not.")]
|
||||
pub decis: bool,
|
||||
|
||||
@ -12,7 +12,7 @@ mod terminal;
|
||||
mod utils;
|
||||
mod widgets;
|
||||
|
||||
use app::App;
|
||||
use app::{App, AppArgs};
|
||||
use args::Args;
|
||||
use clap::Parser;
|
||||
use color_eyre::Result;
|
||||
@ -43,7 +43,7 @@ async fn main() -> Result<()> {
|
||||
};
|
||||
|
||||
// merge `Args` and `AppStorage`.
|
||||
let app_args = (args, stg).into();
|
||||
let app_args: AppArgs = (args, stg).into();
|
||||
let app_storage = App::new(app_args).run(terminal, events).await?.to_storage();
|
||||
// store app state persistantly
|
||||
storage.save(app_storage)?;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user