From d45cd729e84b756633e17dd35c6ea090c7c57524 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 3 Jan 2025 18:05:48 -0800 Subject: [PATCH] feat(cli): allow checking of arbitrary config files This commit adds an optional --komorebi-config flag to the check command to allow users to check a komorebi.json file in an arbitrary location. --- komorebic/src/main.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 8f6ce2ae..eec27bf3 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -922,6 +922,13 @@ struct EnableAutostart { masir: bool, } +#[derive(Parser)] +struct Check { + /// Path to a static configuration JSON file + #[clap(action, short, long)] + komorebi_config: Option, +} + #[derive(Parser)] struct ReplaceConfiguration { /// Static configuration JSON file from which the configuration should be loaded @@ -954,7 +961,7 @@ enum SubCommand { /// Kill background processes started by komorebic Kill(Kill), /// Check komorebi configuration and related files for common errors - Check, + Check(Check), /// Show the path to komorebi.json #[clap(alias = "config")] Configuration, @@ -1576,7 +1583,7 @@ fn main() -> Result<()> { std::fs::remove_file(shortcut_file)?; } } - SubCommand::Check => { + SubCommand::Check(args) => { let home_display = HOME_DIR.display(); if HAS_CUSTOM_CONFIG_HOME.load(Ordering::SeqCst) { println!("KOMOREBI_CONFIG_HOME detected: {home_display}\n"); @@ -1591,7 +1598,15 @@ fn main() -> Result<()> { println!("Looking for configuration files in {home_display}\n"); - let static_config = HOME_DIR.join("komorebi.json"); + let static_config = if let Some(static_config) = args.komorebi_config { + println!( + "Using an arbitrary configuration file passed to --komorebi-config flag\n" + ); + static_config + } else { + HOME_DIR.join("komorebi.json") + }; + let config_pwsh = HOME_DIR.join("komorebi.ps1"); let config_ahk = HOME_DIR.join("komorebi.ahk"); let config_whkd = WHKD_CONFIG_DIR.join("whkdrc");