Refactor path expansion into separate function

This commit is contained in:
2021-11-19 22:15:26 +01:00
parent f251c16566
commit 4c1a6c6ed7

View File

@@ -26,18 +26,13 @@ fn env_home() -> PathBuf {
}
}
fn sync_trees(config: Config) {
for tree in config.trees {
let repos = tree.repos.unwrap_or_default();
let root_path = match &tree.root {
Some(root) => {
fn expand_path(path: &Path) -> PathBuf {
fn home_dir() -> Option<PathBuf> {
Some(env_home())
}
let expanded_path = match shellexpand::full_with_context(
&root,
&path_as_string(path),
home_dir,
|name| -> Result<Option<String>, &'static str> {
match name {
@@ -55,9 +50,13 @@ fn sync_trees(config: Config) {
};
Path::new(&expanded_path).to_path_buf()
}
None => std::env::current_dir().unwrap(),
};
}
fn sync_trees(config: Config) {
for tree in config.trees {
let repos = tree.repos.unwrap_or_default();
let root_path = expand_path(Path::new(&tree.root));
for repo in &repos {
let name = &repo.name;