use std::io::IsTerminal;
#[derive(Debug, Clone)]
pub struct CliContext {
pub non_interactive: bool,
}
impl CliContext {
pub fn new(explicit_non_interactive: bool) -> Self {
let non_interactive = explicit_non_interactive || !std::io::stdin().is_terminal();
Self { non_interactive }
}
pub fn is_non_interactive(&self) -> bool {
self.non_interactive
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_explicit_non_interactive() {
let ctx = CliContext::new(true);
assert!(ctx.is_non_interactive());
}
#[test]
fn test_context_clone() {
let ctx = CliContext::new(true);
let cloned = ctx.clone();
assert_eq!(ctx.non_interactive, cloned.non_interactive);
}
}