diff --git a/lib/crates/fabro-cli/src/commands/doctor.rs b/lib/crates/fabro-cli/src/commands/doctor.rs index fd2cb59cd..5c82a42a0 100644 --- a/lib/crates/fabro-cli/src/commands/doctor.rs +++ b/lib/crates/fabro-cli/src/commands/doctor.rs @@ -335,7 +335,9 @@ pub(crate) async fn run_doctor( title: "Local".to_string(), checks: vec![ check_config( - settings_config_path.filter(|path| path.exists()), + settings_config_path + .exists() + .then_some(settings_config_path), &legacy_config_paths, ), check_legacy_env(legacy_env_path), diff --git a/lib/crates/fabro-cli/src/commands/server/mod.rs b/lib/crates/fabro-cli/src/commands/server/mod.rs index a9f15a3cb..b82e42e85 100644 --- a/lib/crates/fabro-cli/src/commands/server/mod.rs +++ b/lib/crates/fabro-cli/src/commands/server/mod.rs @@ -55,10 +55,12 @@ pub(crate) async fn dispatch(command: ServerCommand, _globals: &GlobalArgs) -> R record_path, serve_args, }) => { - let active_config_path = serve_args - .config - .clone() - .or_else(|| user_config::active_settings_path(None)); + let active_config_path = Some( + serve_args + .config + .clone() + .unwrap_or_else(|| user_config::active_settings_path(None)), + ); let bind_addr = if let Some(s) = serve_args.bind.as_deref() { bind::parse_bind(s)? } else { diff --git a/lib/crates/fabro-cli/src/manifest_builder.rs b/lib/crates/fabro-cli/src/manifest_builder.rs index 8de1c76b1..12e4129d1 100644 --- a/lib/crates/fabro-cli/src/manifest_builder.rs +++ b/lib/crates/fabro-cli/src/manifest_builder.rs @@ -86,7 +86,9 @@ pub(crate) fn build_run_manifest(input: ManifestBuildInput) -> Result Result Result Result { - let config_path = user_config::active_settings_path(None) - .unwrap_or_else(|| PathBuf::from(".fabro/settings.toml")); + let config_path = user_config::active_settings_path(None); let bind = start::ensure_server_running_for_storage(storage_dir, &config_path) .with_context(|| format!("Failed to start fabro server for {}", storage_dir.display()))?; match bind { @@ -169,8 +167,7 @@ pub(crate) async fn connect_server_backed_api_client( let settings = user_config::load_settings()?; let target = user_config::resolve_server_target(args, &settings)?; let runtime = LocalServerRuntime { - active_config_path: user_config::active_settings_path(None) - .unwrap_or_else(|| PathBuf::from(".fabro/settings.toml")), + active_config_path: user_config::active_settings_path(None), storage_dir: settings.storage_dir(), }; connect_target_api_client(&target, &runtime).await diff --git a/lib/crates/fabro-config/src/user.rs b/lib/crates/fabro-config/src/user.rs index ca7bd2a1d..553c4935c 100644 --- a/lib/crates/fabro-config/src/user.rs +++ b/lib/crates/fabro-config/src/user.rs @@ -81,8 +81,8 @@ impl From for ExecSettings { } } -pub fn default_settings_path() -> Option { - Some(Home::from_env().user_config()) +pub fn default_settings_path() -> PathBuf { + Home::from_env().user_config() } pub fn default_socket_path() -> PathBuf { @@ -93,10 +93,10 @@ pub fn legacy_default_storage_root() -> PathBuf { Home::from_env().root().to_path_buf() } -pub fn active_settings_path(path: Option<&Path>) -> Option { +pub fn active_settings_path(path: Option<&Path>) -> PathBuf { path.map(Path::to_path_buf) .or_else(|| std::env::var_os(FABRO_CONFIG_ENV).map(PathBuf::from)) - .or_else(default_settings_path) + .unwrap_or_else(default_settings_path) } pub fn legacy_user_config_path() -> Option { @@ -146,8 +146,7 @@ pub fn load_settings_config(path: Option<&Path>) -> anyhow::Result .flatten() { if legacy_path.is_file() && should_warn_about_legacy_user_config(&legacy_path) { - let target = default_settings_path() - .unwrap_or_else(|| PathBuf::from(format!("~/.fabro/{SETTINGS_CONFIG_FILENAME}"))); + let target = default_settings_path(); eprintln!( "Warning: ignoring legacy config file {}. Rename it to {}.", legacy_path.display(), @@ -210,7 +209,7 @@ mod tests { assert_eq!( default_settings_path(), - Some(home.join(".fabro").join(SETTINGS_CONFIG_FILENAME)) + home.join(".fabro").join(SETTINGS_CONFIG_FILENAME) ); assert_eq!(default_socket_path(), home.join(".fabro/fabro.sock")); assert_eq!( @@ -247,6 +246,6 @@ mod tests { let custom_path = dir.path().join("custom-settings.toml"); let _guard = EnvGuard::set(FABRO_CONFIG_ENV, Some(&custom_path)); - assert_eq!(active_settings_path(None), Some(custom_path)); + assert_eq!(active_settings_path(None), custom_path); } } diff --git a/lib/crates/fabro-server/src/serve.rs b/lib/crates/fabro-server/src/serve.rs index 247899689..ae00ea69c 100644 --- a/lib/crates/fabro-server/src/serve.rs +++ b/lib/crates/fabro-server/src/serve.rs @@ -61,7 +61,7 @@ fn load_settings(path: Option<&Path>) -> anyhow::Result { } fn resolved_config_path(path: Option<&Path>) -> PathBuf { - active_settings_path(path).unwrap_or_else(|| PathBuf::from(".fabro/settings.toml")) + active_settings_path(path) } fn apply_serve_overrides(base: &Settings, args: &ServeArgs, dry_run_mode: bool) -> Settings {