aboutsummaryrefslogtreecommitdiff
path: root/dotup_cli/src/commands
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2021-07-09 10:03:42 -0400
committerdiogo464 <[email protected]>2021-07-09 10:03:42 -0400
commit21c234735ebf74899ce9a98cb46d9500b3f51e89 (patch)
tree6f0f5c5033bc014813ac2b391616f8e7cff35a9c /dotup_cli/src/commands
parent3469dd5ab5b475a96f852b8c2e12a0b2c1c09caf (diff)
Search parent directories for depot file.
If the depot file is not specified and is not found in the current directory then it will be searched trough the parent directories until a depot file is found.
Diffstat (limited to 'dotup_cli/src/commands')
-rw-r--r--dotup_cli/src/commands/utils.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/dotup_cli/src/commands/utils.rs b/dotup_cli/src/commands/utils.rs
index 4160078..706266e 100644
--- a/dotup_cli/src/commands/utils.rs
+++ b/dotup_cli/src/commands/utils.rs
@@ -2,6 +2,8 @@ use std::path::{Path, PathBuf};
2 2
3use crate::prelude::*; 3use crate::prelude::*;
4 4
5const DEFAULT_DEPOT_NAME: &str = "depot.toml";
6
5pub fn home_directory() -> anyhow::Result<PathBuf> { 7pub fn home_directory() -> anyhow::Result<PathBuf> {
6 match std::env::var("HOME") { 8 match std::env::var("HOME") {
7 Ok(val) => Ok(PathBuf::from(val)), 9 Ok(val) => Ok(PathBuf::from(val)),
@@ -12,6 +14,18 @@ pub fn home_directory() -> anyhow::Result<PathBuf> {
12 } 14 }
13} 15}
14 16
17pub fn find_archive_path() -> anyhow::Result<PathBuf> {
18 let mut start = PathBuf::new();
19 while {
20 start.push(DEFAULT_DEPOT_NAME);
21 !start.is_file()
22 } {
23 start.pop();
24 start.push("..");
25 }
26 Ok(start.canonicalize()?)
27}
28
15pub fn write_archive(path: impl AsRef<Path>, archive: &Archive) -> anyhow::Result<()> { 29pub fn write_archive(path: impl AsRef<Path>, archive: &Archive) -> anyhow::Result<()> {
16 let path = path.as_ref(); 30 let path = path.as_ref();
17 log::debug!("Writing archive to {}", path.display()); 31 log::debug!("Writing archive to {}", path.display());