1use super::{CommandSpec, INDEX_DB_FILE};
2use std::env;
3use std::ffi::OsString;
4use std::path::PathBuf;
5
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct EvoPaths {
8 pub home: PathBuf,
9 pub commands_dir: PathBuf,
10 pub index_db: PathBuf,
11}
12
13impl EvoPaths {
14 pub fn new(home: PathBuf) -> Self {
15 Self {
16 commands_dir: home.join("cmds"),
17 index_db: home.join(INDEX_DB_FILE),
18 home,
19 }
20 }
21
22 pub fn from_env() -> Self {
23 if let Some(path) = env::var_os("EVO_HOME") {
24 return Self::new(PathBuf::from(path));
25 }
26
27 let home = env::var_os("HOME").unwrap_or_else(|| OsString::from("."));
28 Self::new(PathBuf::from(home).join(".evo"))
29 }
30
31 pub fn command_spec(&self, name: &str) -> CommandSpec {
32 CommandSpec::new(&self.commands_dir, name)
33 }
34}
35
36impl Default for EvoPaths {
37 fn default() -> Self {
38 Self::from_env()
39 }
40}