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
37
38
39
40
41
42
43
44
45
46
47
|
use {
crate::{
errors::ProgramError,
cli::{Args, ShellInstallState},
},
std::{
env,
},
};
/// launch arguments related to installation
/// (not used by the application after the first step)
pub struct InstallLaunchArgs {
pub install: Option<bool>, // installation is required
pub set_install_state: Option<ShellInstallState>, // the state to set
pub print_shell_function: Option<String>, // shell function to print on stdout
}
impl InstallLaunchArgs {
pub fn from(args: &Args) -> Result<Self, ProgramError> {
let mut install = None;
if let Ok(s) = env::var("BR_INSTALL") {
if s == "yes" {
install = Some(true);
} else if s == "no" {
install = Some(false);
} else {
warn!("Unexpected value of BR_INSTALL: {:?}", s);
}
}
// the cli arguments may override the env var value
if args.install {
install = Some(true);
} else if args.outcmd.is_some() {
install = Some(false);
}
let print_shell_function = args.print_shell_function.clone();
let set_install_state = args.set_install_state;
Ok(Self {
install,
set_install_state,
print_shell_function,
})
}
}
|