Implement `paths` for `Profile`

Signed-off-by: xphoniex <xphoniex@users.noreply.github.com>
This commit is contained in:
xphoniex 2022-11-05 05:27:24 +00:00 committed by Alexis Sellier
parent 5847ad2ff1
commit 357fc79b41
No known key found for this signature in database
1 changed files with 25 additions and 1 deletions

View File

@ -11,7 +11,7 @@
//! radicle.sock # Node control socket
//!
use std::io;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use thiserror::Error;
@ -122,6 +122,11 @@ impl Profile {
.map(PathBuf::from)
.unwrap_or_else(|| self.home.join("node").join(node::DEFAULT_SOCKET_NAME))
}
/// Get `Paths` of profile
pub fn paths(&self) -> Paths {
Paths { home: &self.home }
}
}
/// Get the path to the radicle home folder.
@ -137,3 +142,22 @@ pub fn home() -> Result<PathBuf, io::Error> {
))
}
}
#[derive(Debug, Clone)]
pub struct Paths<'a> {
home: &'a Path,
}
impl Paths<'_> {
pub fn storage(&self) -> PathBuf {
self.home.join("storage")
}
pub fn keys(&self) -> PathBuf {
self.home.join("keys")
}
pub fn node(&self) -> PathBuf {
self.home.join("node")
}
}