Skip to content

Commit

Permalink
feat(clipcatd): search for fallback configuration directories
Browse files Browse the repository at this point in the history
  • Loading branch information
xrelkd committed Apr 21, 2024
1 parent ddf63ea commit ce1e49d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clipcatd/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Cli {
}

fn load_config(&self) -> Result<Config, Error> {
let config_file = &self.config_file.clone().unwrap_or_else(Config::default_path);
let config_file = &self.config_file.clone().unwrap_or_else(Config::search_config_file_path);
let mut config = Config::load(config_file)?;

config.daemonize = !self.no_daemon;
Expand Down
21 changes: 21 additions & 0 deletions clipcatd/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ impl Default for Config {
}

impl Config {
pub fn search_config_file_path() -> PathBuf {
let paths = vec![Self::default_path()]
.into_iter()
.chain(clipcat_base::fallback_project_config_directories().into_iter().map(
|mut path| {
path.push(clipcat_base::DAEMON_CONFIG_NAME);
path
},
))
.collect::<Vec<_>>();
for path in paths {
let Ok(exists) = path.try_exists() else {
continue;
};
if exists {
return path;
}
}
Self::default_path()
}

#[inline]
pub fn default_path() -> PathBuf {
[
Expand Down

0 comments on commit ce1e49d

Please sign in to comment.