-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathenv_variables.rs
More file actions
36 lines (33 loc) · 1.22 KB
/
env_variables.rs
File metadata and controls
36 lines (33 loc) · 1.22 KB
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
36
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
use pet_core::os_environment::Environment;
use std::path::PathBuf;
#[derive(Debug, Clone)]
// NOTE: Do not implement Default trait, as we do not want to ever forget to set the values.
// Lets be explicit, this way we never miss a value (in Windows or Unix).
pub struct EnvVariables {
#[allow(dead_code)]
pub pipenv_max_depth: u16,
pub pipenv_pipfile: String,
pub home: Option<PathBuf>,
pub xdg_data_home: Option<String>,
pub workon_home: Option<PathBuf>,
}
impl EnvVariables {
pub fn from(env: &dyn Environment) -> Self {
EnvVariables {
pipenv_max_depth: env
.get_env_var("PIPENV_MAX_DEPTH".to_string())
.map(|s| s.parse::<u16>().ok().unwrap_or(3))
.unwrap_or(3),
pipenv_pipfile: env
.get_env_var("PIPENV_PIPFILE".to_string())
.unwrap_or("Pipfile".to_string()),
home: env.get_user_home(),
xdg_data_home: env.get_env_var("XDG_DATA_HOME".to_string()),
workon_home: env
.get_env_var("WORKON_HOME".to_string())
.map(PathBuf::from),
}
}
}