use clap::Args;
use crate::color::ColorMode;
use crate::flags::resolve_color;
use crate::format::OutputFormat;
#[cfg_attr(
feature = "view",
doc = "",
doc = "[`Self::view`]: Self::view",
doc = "[`View`]: crate::view::View"
)]
#[cfg_attr(
not(feature = "view"),
doc = "",
doc = "[`Self::view`]: crate#cargo-features",
doc = "[`View`]: crate#cargo-features"
)]
#[derive(Args, Clone, Debug, Default, Eq, PartialEq)]
#[command(about = None, long_about = None)]
#[non_exhaustive]
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"
)]
color: ColorMode,
#[arg(long, global = true, help_heading = "Output")]
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)
}
}
#[cfg_attr(feature = "view", doc = "", doc = "[`Self::view`]: Self::view")]
#[cfg_attr(
not(feature = "view"),
doc = "",
doc = "[`Self::view`]: crate#cargo-features"
)]
#[derive(Args, Clone, Debug, Default, Eq, PartialEq)]
#[command(about = None, long_about = None)]
#[non_exhaustive]
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)
}
}
#[derive(Args, Clone, Debug, Default, Eq, PartialEq)]
#[command(about = None, long_about = None)]
#[non_exhaustive]
pub struct FormatLong {
#[arg(
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 FormatLong {
#[cfg(feature = "view")]
#[must_use]
pub fn view(&self, color: ColorMode) -> crate::view::View {
crate::view::View::new(self.format, color).quiet(self.quiet)
}
}