aboutsummaryrefslogtreecommitdiff
path: root/dotup_cli/src/commands/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'dotup_cli/src/commands/utils.rs')
-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());