feat: prefer installed config file location
This commit is contained in:
+1
-1
@@ -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",
|
||||
|
||||
+28
-7
@@ -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<PathBuf>,
|
||||
|
||||
#[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>) -> 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 => {
|
||||
|
||||
Reference in New Issue
Block a user