1 | use crate::error::{Error, Result}; |
2 | use std::env; |
3 | |
4 | #[derive(PartialEq, Debug)] |
5 | pub enum Update { |
6 | Wip, |
7 | Overwrite, |
8 | } |
9 | |
10 | impl Default for Update { |
11 | fn default() -> Self { |
12 | Update::Wip |
13 | } |
14 | } |
15 | |
16 | impl Update { |
17 | pub fn env() -> Result<Self> { |
18 | let var = match env::var_os("TRYBUILD" ) { |
19 | Some(var) => var, |
20 | None => return Ok(Update::default()), |
21 | }; |
22 | |
23 | match var.as_os_str().to_str() { |
24 | Some("wip" ) => Ok(Update::Wip), |
25 | Some("overwrite" ) => Ok(Update::Overwrite), |
26 | _ => Err(Error::UpdateVar(var)), |
27 | } |
28 | } |
29 | } |
30 | |