Refactor path expansion into separate function
This commit is contained in:
17
src/lib.rs
17
src/lib.rs
@@ -26,18 +26,13 @@ fn env_home() -> PathBuf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync_trees(config: Config) {
|
fn expand_path(path: &Path) -> PathBuf {
|
||||||
for tree in config.trees {
|
|
||||||
let repos = tree.repos.unwrap_or_default();
|
|
||||||
|
|
||||||
let root_path = match &tree.root {
|
|
||||||
Some(root) => {
|
|
||||||
fn home_dir() -> Option<PathBuf> {
|
fn home_dir() -> Option<PathBuf> {
|
||||||
Some(env_home())
|
Some(env_home())
|
||||||
}
|
}
|
||||||
|
|
||||||
let expanded_path = match shellexpand::full_with_context(
|
let expanded_path = match shellexpand::full_with_context(
|
||||||
&root,
|
&path_as_string(path),
|
||||||
home_dir,
|
home_dir,
|
||||||
|name| -> Result<Option<String>, &'static str> {
|
|name| -> Result<Option<String>, &'static str> {
|
||||||
match name {
|
match name {
|
||||||
@@ -56,8 +51,12 @@ fn sync_trees(config: Config) {
|
|||||||
|
|
||||||
Path::new(&expanded_path).to_path_buf()
|
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 {
|
for repo in &repos {
|
||||||
let name = &repo.name;
|
let name = &repo.name;
|
||||||
|
|||||||
Reference in New Issue
Block a user