Skip to content

Commit

Permalink
fix(cli): allow checking of arbitrary config files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LGUG2Z committed Jan 4, 2025
1 parent 4b9d811 commit 9c1c700
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
}

#[derive(Parser)]
struct ReplaceConfiguration {
/// Static configuration JSON file from which the configuration should be loaded
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down

0 comments on commit 9c1c700

Please sign in to comment.