aboutsummaryrefslogtreecommitdiff
path: root/dotup_cli/src/commands/link.rs
diff options
context:
space:
mode:
Diffstat (limited to 'dotup_cli/src/commands/link.rs')
-rw-r--r--dotup_cli/src/commands/link.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/dotup_cli/src/commands/link.rs b/dotup_cli/src/commands/link.rs
index 4c1ae06..66194e1 100644
--- a/dotup_cli/src/commands/link.rs
+++ b/dotup_cli/src/commands/link.rs
@@ -22,6 +22,8 @@ pub struct Opts {
22 paths: Vec<PathBuf>, 22 paths: Vec<PathBuf>,
23} 23}
24 24
25// TODO: require destination
26// remove else branch
25pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { 27pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> {
26 let mut depot = utils::read_depot(&config.archive_path)?; 28 let mut depot = utils::read_depot(&config.archive_path)?;
27 29
@@ -43,7 +45,7 @@ pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> {
43 } else { 45 } else {
44 let mut params = Vec::new(); 46 let mut params = Vec::new();
45 for origin in origins { 47 for origin in origins {
46 link(&depot, origin, destination, origin, &mut params)?; 48 generate_link_params(&depot, origin, destination, origin, &mut params)?;
47 } 49 }
48 params 50 params
49 }; 51 };
@@ -69,7 +71,7 @@ pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> {
69 Ok(()) 71 Ok(())
70} 72}
71 73
72fn link( 74fn generate_link_params(
73 depot: &Depot, 75 depot: &Depot,
74 origin: &Path, 76 origin: &Path,
75 destination: &Path, 77 destination: &Path,
@@ -78,14 +80,14 @@ fn link(
78) -> anyhow::Result<()> { 80) -> anyhow::Result<()> {
79 let metadata = std::fs::metadata(origin)?; 81 let metadata = std::fs::metadata(origin)?;
80 if metadata.is_file() { 82 if metadata.is_file() {
81 link_file(depot, origin, destination, base, params)?; 83 generate_file_link_params(depot, origin, destination, base, params)?;
82 } else if metadata.is_dir() { 84 } else if metadata.is_dir() {
83 link_directory_recursive(depot, origin, destination, base, params)?; 85 generate_directory_link_params_recursive(depot, origin, destination, base, params)?;
84 } 86 }
85 Ok(()) 87 Ok(())
86} 88}
87 89
88fn link_file( 90fn generate_file_link_params(
89 depot: &Depot, 91 depot: &Depot,
90 origin: &Path, 92 origin: &Path,
91 destination: &Path, 93 destination: &Path,
@@ -118,7 +120,7 @@ fn link_file(
118 Ok(()) 120 Ok(())
119} 121}
120 122
121fn link_directory_recursive( 123fn generate_directory_link_params_recursive(
122 depot: &Depot, 124 depot: &Depot,
123 dir_path: &Path, 125 dir_path: &Path,
124 destination: &Path, 126 destination: &Path,
@@ -127,7 +129,7 @@ fn link_directory_recursive(
127) -> anyhow::Result<()> { 129) -> anyhow::Result<()> {
128 for origin in dir_path.read_dir()? { 130 for origin in dir_path.read_dir()? {
129 let origin = origin?.path(); 131 let origin = origin?.path();
130 link(depot, &origin, destination, base, params)?; 132 generate_link_params(depot, &origin, destination, base, params)?;
131 } 133 }
132 Ok(()) 134 Ok(())
133} 135}