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
use std::path::PathBuf;
const ORGANIZATION: &'static str = "GolemFactory";
pub trait Env {
fn data_directory(&self, runtime_name: &str) -> anyhow::Result<PathBuf>;
fn args(&self) -> Box<dyn Iterator<Item = String>> {
Box::new(std::env::args())
}
}
#[derive(Clone, Copy, Debug, Default)]
pub struct DefaultEnv;
impl Env for DefaultEnv {
fn data_directory(&self, runtime_name: &str) -> anyhow::Result<PathBuf> {
Ok(
directories::ProjectDirs::from("", ORGANIZATION, runtime_name)
.map(|dirs| dirs.data_dir().into())
.unwrap_or_else(|| PathBuf::from(ORGANIZATION).join(runtime_name)),
)
}
}