2 use std::path::PathBuf;
4 pub struct Configuration {
5 // Default Base Directories, default to XDG dirs but can be
6 pub output_directory: PathBuf,
11 pub fn new() -> Self {
12 let output_directory = Configuration::directory(
13 "PAGE_OUTPUT_DIRECTORY",
24 fn directory(user_override: &str, default_value: &str, home_fallback: &str, path: &str) -> PathBuf {
25 match env::var(user_override) {
26 Ok(directory) => PathBuf::from(directory),
27 Err(_) => match env::var(default_value) {
28 Ok(directory) => PathBuf::from(directory),
29 Err(_) => match env::var("HOME") {
30 Ok(directory) => PathBuf::from(directory).join(home_fallback),
31 Err(_) => panic!("Could not find required directory, {} or {} should be set and readable.", user_override, default_value),