1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use std::fs;

/// Returns the Gut path directory as a String
///
/// This function will panic if it fails to get the user's home directory.
pub fn get_gut_dir() -> String {
  let home_dir = match dirs::home_dir() {
    Some(dir) => dir,
    None => panic!("Failed to find home directory"),
  };

  let home = match home_dir.to_str() {
    Some(dir) => dir.to_string(),
    None => panic!("Failed to convert home directory to string"),
  };

  format!("{}/{}", home, ".gut")
}

pub fn create_gut_dir() {
  fs::create_dir_all(get_gut_dir()).expect("Failed to create gut directory");
}

#[cfg(test)]
mod tests {
  #[test]
  fn create_gut_dir() {
    super::create_gut_dir()
  }

  #[test]
  fn get_gut_dir() {
    assert!(super::get_gut_dir().contains("/.gut"));
  }
}