From dc6ec72e77bbf36073861431545f3f9159dfbb7e Mon Sep 17 00:00:00 2001 From: David Perl Date: Thu, 30 Jul 2026 12:12:33 +0200 Subject: [PATCH] feat: prefer installed config file location --- data/defaults.json | 2 +- src/main.rs | 35 ++++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/data/defaults.json b/data/defaults.json index 6afdaa1..718f8d1 100644 --- a/data/defaults.json +++ b/data/defaults.json @@ -1,5 +1,5 @@ { - "deployments_base": "/sls/mx/applications/aaredaq", + "deployments_base": "/sls/mx/applications/AareDAQ", "default_venv_name": ".venv", "default_gui_file": "src/aare/gui/gui.py", "default_server_file": "src/aare/daq/server.py", diff --git a/src/main.rs b/src/main.rs index 7bb350d..d345401 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,17 +10,37 @@ use clap::{Parser, Subcommand}; use config::{Config, LauncherEntry, load_config}; use detect::detect_beamline; +/// Config file installed by the RPM, preferred when it exists. +const INSTALLED_CONFIG: &str = "/etc/aarel/defaults.json"; +/// Config file shipped in the source tree, used as a fallback. +const LOCAL_CONFIG: &str = "data/defaults.json"; + #[derive(Parser)] #[command(name = "aarel")] struct Cli { - /// Path to the launcher config file. - #[arg(long, default_value = "data/defaults.json")] - config: PathBuf, + /// Path to the launcher config file. Defaults to /etc/aarel/defaults.json, + /// falling back to ./data/defaults.json. + #[arg(long)] + config: Option, #[command(subcommand)] command: Command, } +/// Resolve the config path: the explicit `--config`, else the installed config +/// if present, else the local one. +fn resolve_config_path(config: Option) -> PathBuf { + if let Some(path) = config { + return path; + } + let installed = PathBuf::from(INSTALLED_CONFIG); + if installed.is_file() { + installed + } else { + PathBuf::from(LOCAL_CONFIG) + } +} + #[derive(Subcommand)] enum Command { /// Enter the TUI to choose what to launch @@ -45,12 +65,13 @@ enum Command { fn main() -> Result<()> { let cli = Cli::parse(); - let json = std::fs::read_to_string(&cli.config) - .with_context(|| format!("failed to read config file {}", cli.config.display()))?; + let config_path = resolve_config_path(cli.config); + let json = std::fs::read_to_string(&config_path) + .with_context(|| format!("failed to read config file {}", config_path.display()))?; let config = load_config(&json)?; - check_base_exists("deployments_base", &config.deployments_base, &cli.config)?; - check_base_exists("venvs_base", &config.deployments_base, &cli.config)?; + check_base_exists("deployments_base", &config.deployments_base, &config_path)?; + check_base_exists("venvs_base", &config.deployments_base, &config_path)?; match cli.command { Command::Pick => {