mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-01 10:41:03 +02:00
feat(cli): debug flag
This commit is contained in:
parent
a0cb01ae5f
commit
7413f78e04
3 changed files with 23 additions and 3 deletions
|
@ -15,6 +15,11 @@ pub struct Args {
|
||||||
#[arg(long("print-schema"))]
|
#[arg(long("print-schema"))]
|
||||||
pub print_schema: bool,
|
pub print_schema: bool,
|
||||||
|
|
||||||
|
/// Print debug information to stderr
|
||||||
|
/// TODO: Make bar follow this too
|
||||||
|
#[arg(long)]
|
||||||
|
pub debug: bool,
|
||||||
|
|
||||||
/// `bar_id` argument passed by `swaybar_command`.
|
/// `bar_id` argument passed by `swaybar_command`.
|
||||||
/// Not used.
|
/// Not used.
|
||||||
#[arg(short('b'), hide(true))]
|
#[arg(short('b'), hide(true))]
|
||||||
|
|
|
@ -8,7 +8,7 @@ use tokio::net::UnixStream;
|
||||||
impl Ipc {
|
impl Ipc {
|
||||||
/// Sends a command to the IPC server.
|
/// Sends a command to the IPC server.
|
||||||
/// The server response is returned.
|
/// The server response is returned.
|
||||||
pub async fn send(&self, command: Command) -> Result<Response> {
|
pub async fn send(&self, command: Command, debug: bool) -> Result<Response> {
|
||||||
let mut stream = match UnixStream::connect(&self.path).await {
|
let mut stream = match UnixStream::connect(&self.path).await {
|
||||||
Ok(stream) => Ok(stream),
|
Ok(stream) => Ok(stream),
|
||||||
Err(err) => Err(Report::new(err)
|
Err(err) => Err(Report::new(err)
|
||||||
|
@ -17,6 +17,11 @@ impl Ipc {
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
let write_buffer = serde_json::to_vec(&command)?;
|
let write_buffer = serde_json::to_vec(&command)?;
|
||||||
|
|
||||||
|
if debug {
|
||||||
|
eprintln!("REQUEST JSON: {}", serde_json::to_string(&command)?);
|
||||||
|
}
|
||||||
|
|
||||||
stream.write_all(&write_buffer).await?;
|
stream.write_all(&write_buffer).await?;
|
||||||
|
|
||||||
let mut read_buffer = vec![0; 1024];
|
let mut read_buffer = vec![0; 1024];
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -85,11 +85,21 @@ fn run_with_args() {
|
||||||
|
|
||||||
match args.command {
|
match args.command {
|
||||||
Some(command) => {
|
Some(command) => {
|
||||||
|
if args.debug {
|
||||||
|
eprintln!("REQUEST: {command:?}")
|
||||||
|
}
|
||||||
|
|
||||||
let rt = create_runtime();
|
let rt = create_runtime();
|
||||||
rt.block_on(async move {
|
rt.block_on(async move {
|
||||||
let ipc = ipc::Ipc::new();
|
let ipc = ipc::Ipc::new();
|
||||||
match ipc.send(command).await {
|
match ipc.send(command, args.debug).await {
|
||||||
Ok(res) => cli::handle_response(res),
|
Ok(res) => {
|
||||||
|
if args.debug {
|
||||||
|
eprintln!("RESPONSE: {res:?}")
|
||||||
|
}
|
||||||
|
|
||||||
|
cli::handle_response(res, args.format.unwrap_or_default())
|
||||||
|
}
|
||||||
Err(err) => error!("{err:?}"),
|
Err(err) => error!("{err:?}"),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue