use std::sync::OnceLock;
#[derive(Debug)]
pub struct RuntimeFlags {
pub show_child_processes: bool,
pub show_output: bool,
pub phases_debug: bool,
pub graph_stats: bool,
pub json_mode: bool,
pub quiet: bool,
pub all_fields: bool,
pub fields_only: bool,
pub color_enabled: bool,
}
static FLAGS: OnceLock<RuntimeFlags> = OnceLock::new();
pub fn init(flags: RuntimeFlags) {
FLAGS.set(flags).expect("runtime flags already initialized");
}
#[cfg(test)]
pub fn init_for_test() {
let _ = FLAGS.set(RuntimeFlags {
show_child_processes: false,
show_output: false,
phases_debug: false,
graph_stats: false,
json_mode: false,
quiet: true,
all_fields: false,
fields_only: false,
color_enabled: false,
});
}
fn get() -> &'static RuntimeFlags {
FLAGS.get().expect("runtime flags not initialized")
}
pub fn show_child_processes() -> bool {
get().show_child_processes
}
pub fn show_output() -> bool {
get().show_output
}
pub fn phases_debug() -> bool {
get().phases_debug
}
pub fn graph_stats() -> bool {
get().graph_stats
}
pub fn json_mode() -> bool {
get().json_mode
}
pub fn quiet() -> bool {
get().quiet
}
pub fn all_fields() -> bool {
FLAGS.get().is_some_and(|f| f.all_fields)
}
pub fn fields_only() -> bool {
FLAGS.get().is_some_and(|f| f.fields_only)
}
pub fn color_enabled() -> bool {
FLAGS.get().is_some_and(|f| f.color_enabled)
}
pub fn quiet_or_default() -> bool {
FLAGS.get().is_some_and(|f| f.quiet)
}
pub fn json_mode_or_default() -> bool {
FLAGS.get().is_some_and(|f| f.json_mode)
}