1use clap::Args;
2
3use crate::color::ColorMode;
4use crate::flags::resolve_color;
5use crate::format::OutputFormat;
6
7#[derive(Args, Clone, Debug, Default, Eq, PartialEq)]
12pub struct OutputArgs {
13 #[arg(
15 short = 'f',
16 long,
17 global = true,
18 value_enum,
19 default_value = "pretty",
20 help_heading = "Output"
21 )]
22 pub format: OutputFormat,
23 #[arg(
25 short = 'c',
26 long,
27 global = true,
28 value_enum,
29 default_value = "auto",
30 help_heading = "Output"
31 )]
32 pub color: ColorMode,
33 #[arg(long, global = true, help_heading = "Output")]
35 pub no_color: bool,
36 #[arg(short = 'q', long, global = true, help_heading = "Output")]
38 pub quiet: bool,
39}
40
41impl OutputArgs {
42 #[must_use]
44 pub fn color(&self) -> ColorMode {
45 resolve_color(self.color, self.no_color)
46 }
47
48 #[cfg(feature = "view")]
50 #[must_use]
51 pub fn view(&self) -> crate::view::View {
52 crate::view::View::new(self.format, self.color()).quiet(self.quiet)
53 }
54}
55
56#[derive(Args, Clone, Debug, Default, Eq, PartialEq)]
58pub struct FormatArgs {
59 #[arg(
61 short = 'f',
62 long,
63 global = true,
64 value_enum,
65 default_value = "pretty",
66 help_heading = "Output"
67 )]
68 pub format: OutputFormat,
69 #[arg(short = 'q', long, global = true, help_heading = "Output")]
71 pub quiet: bool,
72}
73
74impl FormatArgs {
75 #[cfg(feature = "view")]
77 #[must_use]
78 pub fn view(&self, color: ColorMode) -> crate::view::View {
79 crate::view::View::new(self.format, color).quiet(self.quiet)
80 }
81}