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_venv_name": ".venv",
|
||||||
"default_gui_file": "src/aare/gui/gui.py",
|
"default_gui_file": "src/aare/gui/gui.py",
|
||||||
"default_server_file": "src/aare/daq/server.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 config::{Config, LauncherEntry, load_config};
|
||||||
use detect::detect_beamline;
|
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)]
|
#[derive(Parser)]
|
||||||
#[command(name = "aarel")]
|
#[command(name = "aarel")]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
/// Path to the launcher config file.
|
/// Path to the launcher config file. Defaults to /etc/aarel/defaults.json,
|
||||||
#[arg(long, default_value = "data/defaults.json")]
|
/// falling back to ./data/defaults.json.
|
||||||
config: PathBuf,
|
#[arg(long)]
|
||||||
|
config: Option<PathBuf>,
|
||||||
|
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: Command,
|
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)]
|
#[derive(Subcommand)]
|
||||||
enum Command {
|
enum Command {
|
||||||
/// Enter the TUI to choose what to launch
|
/// Enter the TUI to choose what to launch
|
||||||
@@ -45,12 +65,13 @@ enum Command {
|
|||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
let json = std::fs::read_to_string(&cli.config)
|
let config_path = resolve_config_path(cli.config);
|
||||||
.with_context(|| format!("failed to read config file {}", cli.config.display()))?;
|
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)?;
|
let config = load_config(&json)?;
|
||||||
|
|
||||||
check_base_exists("deployments_base", &config.deployments_base, &cli.config)?;
|
check_base_exists("deployments_base", &config.deployments_base, &config_path)?;
|
||||||
check_base_exists("venvs_base", &config.deployments_base, &cli.config)?;
|
check_base_exists("venvs_base", &config.deployments_base, &config_path)?;
|
||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Command::Pick => {
|
Command::Pick => {
|
||||||
|
|||||||
Reference in New Issue
Block a user