feat: return correct exit code

man-page
Moritz Böhme 2023-07-29 16:52:39 +02:00
parent 56beda6840
commit a947a2db2a
Signed by: moritz
GPG Key ID: 970C6E89EB0547A9
3 changed files with 16 additions and 19 deletions

View File

@ -45,7 +45,7 @@ pub enum Command {
/// Pomodoro specific command
#[command(subcommand)]
#[clap(visible_alias = "p")]
Pomodoro(PomodoroCommand)
Pomodoro(PomodoroCommand),
}
#[derive(Debug, Subcommand)]
@ -86,7 +86,7 @@ fn get_stream(socket_path: &String) -> Result<UnixStream> {
.context(format!("Could not connect to socket {}!", socket_path))
}
pub fn send_command(socket_path: &String, command: OtherCommand) -> Result<()> {
pub fn send_command(socket_path: &String, command: OtherCommand) -> Result<Answer> {
let stream = get_stream(socket_path)?;
serde_cbor::to_writer(&stream, &command).context("Could not write command!")?;
stream
@ -94,9 +94,5 @@ pub fn send_command(socket_path: &String, command: OtherCommand) -> Result<()> {
.context("Could not shutdown write!")?;
let answer: Result<Answer, AnswerErr> =
serde_cbor::from_reader(&stream).context("Could not read answer!")?;
match answer {
Ok(answer) => println!("{}", answer),
Err(err) => println!("Error: {}", err),
}
Ok(())
Ok(answer?)
}

View File

@ -36,7 +36,7 @@ pub enum Answer {
impl Display for Answer {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
Answer::Ok => write!(f, "Ok"),
Answer::Ok => write!(f, ""),
Answer::Timers(timers) => {
if timers.is_empty() {
writeln!(f, "No timers running.")

View File

@ -5,11 +5,10 @@ pub mod timer;
use crate::cli::{send_command, Cli, Command as CliCommand};
use crate::daemon::{Command as DaemonCommand, Daemon};
use anyhow::Result;
use clap::Parser;
use cli::PomodoroCommand;
fn main() -> Result<()> {
fn main() -> Result<(), anyhow::Error> {
let args = Cli::parse();
let daemon_command = match args.command {
CliCommand::Daemon { no_notify } => return Daemon::new(args.socket, no_notify)?.run(),
@ -34,5 +33,7 @@ fn main() -> Result<()> {
PomodoroCommand::List => DaemonCommand::PomodoroList,
},
};
send_command(&args.socket, daemon_command)
let answer = send_command(&args.socket, daemon_command)?;
print!("{}", answer);
Ok(())
}