use clap::Args;
use crate::color::ColorMode;
use crate::flags::resolve_color;
use crate::format::OutputFormat;
#[derive(Args, Clone, Debug, Default, Eq, PartialEq)]
pub struct OutputArgs {
#[arg(
short = 'f',
long,
global = true,
value_enum,
default_value = "pretty",
help_heading = "Output"
)]
pub format: OutputFormat,
#[arg(
short = 'c',
long,
global = true,
value_enum,
default_value = "auto",
help_heading = "Output"
)]
pub color: ColorMode,
#[arg(long, global = true, help_heading = "Output")]
pub no_color: bool,
#[arg(short = 'q', long, global = true, help_heading = "Output")]
pub quiet: bool,
}
impl OutputArgs {
#[must_use]
pub fn color(&self) -> ColorMode {
resolve_color(self.color, self.no_color)
}
#[cfg(feature = "view")]
#[must_use]
pub fn view(&self) -> crate::view::View {
crate::view::View::new(self.format, self.color()).quiet(self.quiet)
}
}
#[derive(Args, Clone, Debug, Default, Eq, PartialEq)]
pub struct FormatArgs {
#[arg(
short = 'f',
long,
global = true,
value_enum,
default_value = "pretty",
help_heading = "Output"
)]
pub format: OutputFormat,
#[arg(short = 'q', long, global = true, help_heading = "Output")]
pub quiet: bool,
}
impl FormatArgs {
#[cfg(feature = "view")]
#[must_use]
pub fn view(&self, color: ColorMode) -> crate::view::View {
crate::view::View::new(self.format, color).quiet(self.quiet)
}
}