Connect applications to schemes, filetypes, and more on macOS (more to come)
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Changed logic to prefer XDG vars over traditional locations

Feel this strikes the best of all worlds

+21 -20
+3 -3
infat-cli/src/main.rs
··· 3 3 eyre::{Context, Result}, 4 4 owo_colors::OwoColorize, 5 5 }; 6 - use infat_lib::{app, association, config, macos::launch_services_db, GlobalOptions}; 6 + use infat_lib::{GlobalOptions, app, association, config, macos::launch_services_db}; 7 7 use std::path::PathBuf; 8 8 use tracing::info; 9 9 ··· 73 73 } 74 74 path.clone() 75 75 } 76 - None => config::find_config_file().ok_or_else(|| { 76 + None => config::find_config_file()?.ok_or_else(|| { 77 77 color_eyre::eyre::eyre!( 78 78 "No configuration file found. Use {} or place config at default location", 79 79 "--config".bright_yellow() ··· 418 418 Some(path) => path.clone(), 419 419 None => { 420 420 let paths = config::get_config_paths(); 421 - paths 421 + paths? 422 422 .first() 423 423 .ok_or_else(|| color_eyre::eyre::eyre!("Could not determine config path"))? 424 424 .clone()
+18 -17
infat-lib/src/config.rs
··· 94 94 } 95 95 96 96 /// Get XDG-compliant configuration file paths in order of preference 97 - pub fn get_config_paths() -> Vec<std::path::PathBuf> { 97 + pub fn get_config_paths() -> Result<Vec<std::path::PathBuf>> { 98 98 let mut paths = Vec::new(); 99 99 100 - // User config directory ($XDG_CONFIG_HOME or ~/.config) 100 + // User-specified configuration directory 101 + let xdg_config_dirs = std::env::var("XDG_CONFIG_HOME"); 102 + 103 + if let Ok(xdg_config) = xdg_config_dirs { 104 + paths.push( 105 + std::path::PathBuf::from(xdg_config) 106 + .join("infat") 107 + .join("config.toml"), 108 + ); 109 + } 110 + 111 + // Default configuration directory ($XDG_CONFIG_HOME or ~/Library/Application Support) 101 112 if let Some(config_dir) = dirs::config_dir() { 102 113 paths.push(config_dir.join("infat").join("config.toml")); 103 114 } 104 115 105 - // System config directories from $XDG_CONFIG_DIRS or fallback 106 - let xdg_config_dirs = 107 - std::env::var("XDG_CONFIG_DIRS").unwrap_or_else(|_| "/etc/xdg".to_string()); 108 - 109 - for dir in xdg_config_dirs.split(':') { 110 - if !dir.is_empty() { 111 - paths.push( 112 - std::path::PathBuf::from(dir) 113 - .join("infat") 114 - .join("config.toml"), 115 - ); 116 - } 116 + if paths.is_empty() { 117 + return Err(InfatError::Generic { message: "Couldn't derive a configuration location, please file an issue -- until it's resolved, please set XDG_CONFIG_HOME".to_string() }); 117 118 } 118 119 119 - paths 120 + Ok(paths) 120 121 } 121 122 122 123 /// Find the first existing configuration file 123 - pub fn find_config_file() -> Option<std::path::PathBuf> { 124 - get_config_paths().into_iter().find(|path| path.exists()) 124 + pub fn find_config_file() -> Result<Option<std::path::PathBuf>> { 125 + Ok(get_config_paths()?.into_iter().find(|path| path.exists())) 125 126 } 126 127 127 128 /// Apply configuration settings