timers/src/main.rs

57 lines
1.9 KiB
Rust

mod cli;
mod daemon;
mod helper;
mod notification;
mod pomodoro;
mod timer;
use crate::cli::{send_command, Cli, Command as CliCommand};
use crate::daemon::{Command as DaemonCommand, Daemon};
use clap::CommandFactory;
use clap::Parser;
use cli::PomodoroCommand;
fn main() -> Result<(), anyhow::Error> {
let args = Cli::parse();
let daemon_command = match args.command {
CliCommand::Daemon {
no_notify,
pid_file,
} => {
return Daemon::new(args.socket, pid_file, no_notify)?.run();
}
CliCommand::Add { name, duration } => {
DaemonCommand::Add(name.into_boxed_str(), duration.into())
}
CliCommand::List => DaemonCommand::List,
CliCommand::Remove { name } => DaemonCommand::Remove(name.into_boxed_str()),
CliCommand::Toggle { name } => DaemonCommand::Toggle(name.into_boxed_str()),
CliCommand::Pomodoro(pomodoro) => match pomodoro {
PomodoroCommand::Start {
work,
pause,
long_pause,
pauses_till_long,
} => DaemonCommand::PomodoroStart {
work: work.into(),
pause: pause.into(),
long_pause: long_pause.into(),
pauses_till_long,
},
PomodoroCommand::Remove => DaemonCommand::PomodoroRemove,
PomodoroCommand::List => DaemonCommand::PomodoroList,
PomodoroCommand::Toggle => DaemonCommand::PomodoroToggle,
},
CliCommand::Completions { shell } => {
shell.generate(&mut Cli::command(), &mut std::io::stdout());
return Ok(());
}
};
let answer = send_command(&args.socket, daemon_command)?;
if args.json {
println!("{}", serde_json::to_string(&answer)?)
} else {
print!("{}", answer);
};
Ok(())
}