This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cfg_dir function to get/create .wash directory
Signed-off-by: Matt Wilkinson <mattwilki17@gmail.com>
- Loading branch information
Matt Wilkinson
committed
Dec 12, 2021
1 parent
70d4489
commit 3c37147
Showing
3 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use crate::util::Result; | ||
use std::{ | ||
fs, | ||
io::{Error, ErrorKind}, | ||
path::PathBuf, | ||
}; | ||
|
||
const WASH_DIR: &str = ".wash"; | ||
|
||
/// Get the path to the `.wash` configuration directory. | ||
/// Creates the directory if it does not exist. | ||
pub fn cfg_dir() -> Result<PathBuf> { | ||
let home = dirs::home_dir().ok_or_else(|| { | ||
Error::new( | ||
ErrorKind::NotFound, | ||
"No home directory found. Please set $HOME.", | ||
) | ||
})?; | ||
|
||
let wash = home.join(WASH_DIR); | ||
|
||
if !wash.exists() { | ||
fs::create_dir_all(&wash)?; | ||
} | ||
|
||
Ok(wash) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters