fix: Improved the first-time run behavior so that it outputs the default configuration file it tries to load to help users locate the file on first-runs
This commit is contained in:
+4
-4
@@ -346,11 +346,11 @@ pub struct AppConfig {
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
pub fn validate(&self) {
|
||||
pub fn validate(&self, config_path: &str) {
|
||||
if self.lidarr.is_none() && self.radarr.is_none() && self.sonarr.is_none() {
|
||||
log_and_print_error(
|
||||
"No Servarr configuration provided in the specified configuration file".to_owned(),
|
||||
);
|
||||
log_and_print_error(format!(
|
||||
"No Servarrs are configured in the file: {config_path}"
|
||||
));
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
|
||||
+15
-10
@@ -2,7 +2,7 @@
|
||||
#[macro_use]
|
||||
extern crate assertables;
|
||||
|
||||
use anyhow::Result;
|
||||
use anyhow::{Context, Result};
|
||||
use clap::{
|
||||
Args, CommandFactory, Parser, crate_authors, crate_description, crate_name, crate_version,
|
||||
};
|
||||
@@ -127,25 +127,30 @@ async fn main() -> Result<()> {
|
||||
let running = Arc::new(AtomicBool::new(true));
|
||||
let r = running.clone();
|
||||
let args = Cli::parse();
|
||||
let config_file_path = confy::get_configuration_file_path("managarr", "config")?;
|
||||
let default_config_path = config_file_path.display().to_string();
|
||||
|
||||
if matches!(args.command, Some(Command::ConfigPath)) {
|
||||
println!(
|
||||
"{}",
|
||||
confy::get_configuration_file_path("managarr", "config")?.display()
|
||||
);
|
||||
|
||||
println!("{default_config_path}");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut config = if let Some(ref config_file) = args.global.config_file {
|
||||
load_config(config_file.to_str().expect("Invalid config file specified"))?
|
||||
let (mut config, config_path) = if let Some(ref config_file) = args.global.config_file {
|
||||
(
|
||||
load_config(config_file.to_str().expect("Invalid config file specified"))?,
|
||||
config_file.display().to_string(),
|
||||
)
|
||||
} else {
|
||||
confy::load("managarr", "config")?
|
||||
(
|
||||
confy::load("managarr", "config")
|
||||
.with_context(|| format!("Config file at '{default_config_path}' is invalid"))?,
|
||||
default_config_path,
|
||||
)
|
||||
};
|
||||
let theme_name = config.theme.clone();
|
||||
let spinner_disabled = args.global.disable_spinner;
|
||||
debug!("Managarr loaded using config: {config:?}");
|
||||
config.validate();
|
||||
config.validate(&config_path);
|
||||
config.post_process_initialization();
|
||||
|
||||
let reqwest_client = build_network_client(&config);
|
||||
|
||||
+1
-1
@@ -146,7 +146,7 @@ pub(super) fn load_config(path: &str) -> Result<AppConfig> {
|
||||
Ok(config)
|
||||
}
|
||||
Err(e) => {
|
||||
log_and_print_error(format!("Unable to open config file: {e:?}"));
|
||||
log_and_print_error(format!("Unable to open config file '{path}': {e:?}"));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user