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
48
49
50
51
use std::fs;
use std::env;
use std::io::prelude::{Read, Write};
use std::path::Path;
use serde_json;
use super::LalResult;
use manifest::create_lal_subdir;
#[derive(Serialize, Deserialize, Clone, Default)]
pub struct StickyOptions {
pub env: Option<String>,
}
impl StickyOptions {
pub fn new() -> StickyOptions { Default::default() }
pub fn read() -> LalResult<StickyOptions> {
let opts_path = Path::new(".lal/opts");
if !opts_path.exists() {
return Ok(StickyOptions::default());
}
let mut opts_data = String::new();
fs::File::open(&opts_path)?.read_to_string(&mut opts_data)?;
let res = serde_json::from_str(&opts_data)?;
Ok(res)
}
pub fn write(&self) -> LalResult<()> {
let pwd = env::current_dir()?;
create_lal_subdir(&pwd)?;
let opts_path = Path::new(".lal/opts");
let encoded = serde_json::to_string_pretty(self)?;
let mut f = fs::File::create(&opts_path)?;
write!(f, "{}\n", encoded)?;
debug!("Wrote {}: \n{}", opts_path.display(), encoded);
Ok(())
}
pub fn delete_local() -> LalResult<()> {
let opts_path = Path::new(".lal/opts");
Ok(fs::remove_file(&opts_path)?)
}
}