From 66bfe25d87cb6b3c8c74a4a4e740ae34bd50cf8c Mon Sep 17 00:00:00 2001 From: undefinedDarkness <38278035+undefinedDarkness@users.noreply.github.com> Date: Wed, 3 Feb 2021 00:29:30 +0530 Subject: [PATCH] Add -c / --config argument to eww daemon (#104) --- src/main.rs | 6 ++++-- src/opts.rs | 6 +++++- src/server.rs | 5 +++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 51fbb95..a0d9061 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,7 +82,7 @@ fn main() { } } - opts::Action::Daemon => { + opts::Action::Daemon { config } => { // make sure that there isn't already a Eww daemon running. if check_server_running(&*IPC_SOCKET_PATH) { eprintln!("Eww server already running."); @@ -90,8 +90,10 @@ fn main() { } else { log::info!("Initializing Eww server."); let _ = std::fs::remove_file(&*crate::IPC_SOCKET_PATH); + println!("Run `eww logs` to see any errors, warnings or information while editing your configuration."); - server::initialize_server()?; + server::initialize_server(config)?; + } } } diff --git a/src/opts.rs b/src/opts.rs index 13f3bcd..ebde049 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -29,7 +29,11 @@ struct RawOpt { pub enum Action { /// Start the Eww daemon. #[structopt(name = "daemon")] - Daemon, + Daemon { + /// Custom Config Path + #[structopt(short, long)] + config: Option, + }, #[structopt(flatten)] ClientOnly(ActionClientOnly), diff --git a/src/server.rs b/src/server.rs index 0da204f..8e9e2f0 100644 --- a/src/server.rs +++ b/src/server.rs @@ -8,7 +8,7 @@ use std::{ }; use tokio::sync::mpsc::*; -pub fn initialize_server() -> Result<()> { +pub fn initialize_server(config_dir_override: Option) -> Result<()> { do_detach()?; simple_signal::set_handler(&[simple_signal::Signal::Int, simple_signal::Signal::Term], move |_| { @@ -20,7 +20,8 @@ pub fn initialize_server() -> Result<()> { }); let (ui_send, mut ui_recv) = tokio::sync::mpsc::unbounded_channel(); - let config_file_path = crate::CONFIG_DIR.join("eww.xml"); + let config_file_path = config_dir_override.unwrap_or(crate::CONFIG_DIR.join("eww.xml")); + let config_dir = config_file_path .parent() .context("config file did not have a parent?!")?