mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-04-19 19:34:24 +02:00
fix(cli): using zero exit code for error responses
This commit is contained in:
parent
a33e0a241a
commit
8dda49477b
2 changed files with 10 additions and 1 deletions
10
src/cli.rs
10
src/cli.rs
|
@ -1,7 +1,9 @@
|
||||||
|
use crate::error::ExitCode;
|
||||||
use crate::ipc::commands::Command;
|
use crate::ipc::commands::Command;
|
||||||
use crate::ipc::responses::Response;
|
use crate::ipc::responses::Response;
|
||||||
use clap::Parser;
|
use clap::{Parser, ValueEnum};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::process::exit;
|
||||||
|
|
||||||
#[derive(Parser, Debug, Serialize, Deserialize)]
|
#[derive(Parser, Debug, Serialize, Deserialize)]
|
||||||
#[command(version)]
|
#[command(version)]
|
||||||
|
@ -38,6 +40,8 @@ pub enum Format {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_response(response: Response, format: Format) {
|
pub fn handle_response(response: Response, format: Format) {
|
||||||
|
let is_err = matches!(response, Response::Err { .. });
|
||||||
|
|
||||||
match format {
|
match format {
|
||||||
Format::Plain => match response {
|
Format::Plain => match response {
|
||||||
Response::Ok => println!("ok"),
|
Response::Ok => println!("ok"),
|
||||||
|
@ -49,4 +53,8 @@ pub fn handle_response(response: Response, format: Format) {
|
||||||
serde_json::to_string(&response).expect("to be valid json")
|
serde_json::to_string(&response).expect("to be valid json")
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if is_err {
|
||||||
|
exit(ExitCode::IpcResponseError as i32)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
pub enum ExitCode {
|
pub enum ExitCode {
|
||||||
GtkDisplay = 1,
|
GtkDisplay = 1,
|
||||||
CreateBars = 2,
|
CreateBars = 2,
|
||||||
|
IpcResponseError = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const ERR_MUTEX_LOCK: &str = "Failed to get lock on Mutex";
|
pub const ERR_MUTEX_LOCK: &str = "Failed to get lock on Mutex";
|
||||||
|
|
Loading…
Add table
Reference in a new issue