dmenv/
settings.rs

1use crate::cli::syntax::Command;
2
3#[derive(Debug, Clone)]
4/// Represent variables that change behavior of
5/// dmenv commands
6pub struct Settings {
7    pub venv_from_stdlib: bool,
8    pub venv_outside_project: bool,
9    pub production: bool,
10    pub system_site_packages: bool,
11}
12
13impl Default for Settings {
14    fn default() -> Settings {
15        Settings {
16            venv_from_stdlib: true,
17            venv_outside_project: false,
18            production: false,
19            system_site_packages: false,
20        }
21    }
22}
23
24impl Settings {
25    /// Construct a new Settings instance using
26    /// options from the command line (the `cmd` parameter)
27    /// and environment variables.
28    //
29    // Note:  Called in `main()` and in test heplers.
30    pub fn from_shell(cmd: &Command) -> Settings {
31        let mut res = Settings {
32            production: cmd.production,
33            system_site_packages: cmd.system_site_packages,
34            ..Default::default()
35        };
36        if std::env::var("DMENV_NO_VENV_STDLIB").is_ok() {
37            res.venv_from_stdlib = false;
38        }
39        if std::env::var("DMENV_VENV_OUTSIDE_PROJECT").is_ok() {
40            res.venv_outside_project = true;
41        }
42        res
43    }
44}