wasm_pack/install/
mode.rs

1use anyhow::{bail, Error, Result};
2use std::str::FromStr;
3
4/// The `InstallMode` determines which mode of initialization we are running, and
5/// what install steps we perform.
6#[derive(Clone, Copy, Debug)]
7pub enum InstallMode {
8    /// Perform all the install steps.
9    Normal,
10    /// Don't install tools like `wasm-bindgen`, just use the global
11    /// environment's existing versions to do builds.
12    Noinstall,
13    /// Skip the rustc version check
14    Force,
15}
16
17impl Default for InstallMode {
18    fn default() -> InstallMode {
19        InstallMode::Normal
20    }
21}
22
23impl FromStr for InstallMode {
24    type Err = Error;
25    fn from_str(s: &str) -> Result<Self> {
26        match s {
27            "no-install" => Ok(InstallMode::Noinstall),
28            "normal" => Ok(InstallMode::Normal),
29            "force" => Ok(InstallMode::Force),
30            _ => bail!("Unknown build mode: {}", s),
31        }
32    }
33}
34
35impl InstallMode {
36    /// Determines if installation is permitted during a function call based on --mode flag
37    pub fn install_permitted(self) -> bool {
38        match self {
39            InstallMode::Normal => true,
40            InstallMode::Force => true,
41            InstallMode::Noinstall => false,
42        }
43    }
44}