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
52
53
54
55
56
use lazy_static::lazy_static;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
pub struct Config {
pub assertions_will_panic: AtomicBool,
pub terminal_width_override: AtomicUsize,
pub update_mode: bool,
}
lazy_static! {
pub static ref CONFIG: Config = Config {
assertions_will_panic: AtomicBool::new(true),
terminal_width_override: AtomicUsize::new(0),
update_mode: is_update_mode(),
};
}
pub fn set_panic(v: bool) {
CONFIG.assertions_will_panic.store(v, Ordering::Relaxed)
}
pub fn should_panic() -> bool {
CONFIG.assertions_will_panic.load(Ordering::Relaxed)
}
pub fn set_terminal_with_override(width: usize) {
CONFIG
.terminal_width_override
.store(width, Ordering::Relaxed);
}
pub fn terminal_width_override() -> usize {
CONFIG.terminal_width_override.load(Ordering::Relaxed)
}
fn is_update_mode() -> bool {
let runtime_var = std::env::var("K9_UPDATE_SNAPSHOTS").map_or(false, |_| true);
let buck_build_id_present = std::env::var("BUCK_BUILD_ID").is_ok();
if !runtime_var && buck_build_id_present {
if option_env!("K9_UPDATE_SNAPSHOTS").is_some() {
return true;
}
}
runtime_var
}