use std::io::IsTerminal;
use crate::render::{self, OutputFormat};
pub fn init_output(bin: &'static str, json: bool) {
let stdout_is_tty = std::io::stdout().is_terminal();
if json || !stdout_is_tty {
render::set_output_format(OutputFormat::Json);
}
render::set_color(color_wanted(stdout_is_tty));
render::set_bin_name(bin);
}
#[must_use]
pub fn color_wanted(is_tty: bool) -> bool {
is_tty && std::env::var_os("NO_COLOR").is_none()
}
#[must_use]
pub fn banner_wanted() -> bool {
std::io::stderr().is_terminal()
}
#[must_use]
pub fn banner_color(code: &'static str) -> &'static str {
if color_wanted(std::io::stderr().is_terminal()) {
code
} else {
""
}
}
pub fn print_completions<C: clap::CommandFactory>(shell: clap_complete::Shell, bin: &str) {
let mut cmd = C::command();
clap_complete::generate(shell, &mut cmd, bin, &mut std::io::stdout());
}