-
Notifications
You must be signed in to change notification settings - Fork 477
Expand file tree
/
Copy pathmode.rs
More file actions
41 lines (37 loc) · 1.14 KB
/
mode.rs
File metadata and controls
41 lines (37 loc) · 1.14 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
37
38
39
40
41
use anyhow::{bail, Error, Result};
use std::str::FromStr;
/// The `InstallMode` determines which mode of initialization we are running, and
/// what install steps we perform.
#[derive(Clone, Copy, Debug)]
#[derive(Default)]
pub enum InstallMode {
/// Perform all the install steps.
#[default]
Normal,
/// Don't install tools like `wasm-bindgen`, just use the global
/// environment's existing versions to do builds.
Noinstall,
/// Skip the rustc version check
Force,
}
impl FromStr for InstallMode {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
match s {
"no-install" => Ok(InstallMode::Noinstall),
"normal" => Ok(InstallMode::Normal),
"force" => Ok(InstallMode::Force),
_ => bail!("Unknown build mode: {}", s),
}
}
}
impl InstallMode {
/// Determines if installation is permitted during a function call based on --mode flag
pub fn install_permitted(self) -> bool {
match self {
InstallMode::Normal => true,
InstallMode::Force => true,
InstallMode::Noinstall => false,
}
}
}