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)]
12#[command(about = None, long_about = None)]
13pub struct OutputArgs {
14 #[arg(
16 short = 'f',
17 long,
18 global = true,
19 value_enum,
20 default_value = "pretty",
21 help_heading = "Output"
22 )]
23 pub format: OutputFormat,
24 #[arg(
26 short = 'c',
27 long,
28 global = true,
29 value_enum,
30 default_value = "auto",
31 help_heading = "Output"
32 )]
33 pub color: ColorMode,
34 #[arg(long, global = true, help_heading = "Output")]
36 pub no_color: bool,
37 #[arg(short = 'q', long, global = true, help_heading = "Output")]
39 pub quiet: bool,
40}
41
42impl OutputArgs {
43 #[must_use]
45 pub fn color(&self) -> ColorMode {
46 resolve_color(self.color, self.no_color)
47 }
48
49 #[cfg(feature = "view")]
51 #[must_use]
52 pub fn view(&self) -> crate::view::View {
53 crate::view::View::new(self.format, self.color()).quiet(self.quiet)
54 }
55}
56
57#[derive(Args, Clone, Debug, Default, Eq, PartialEq)]
59#[command(about = None, long_about = None)]
60pub struct FormatArgs {
61 #[arg(
63 short = 'f',
64 long,
65 global = true,
66 value_enum,
67 default_value = "pretty",
68 help_heading = "Output"
69 )]
70 pub format: OutputFormat,
71 #[arg(short = 'q', long, global = true, help_heading = "Output")]
73 pub quiet: bool,
74}
75
76impl FormatArgs {
77 #[cfg(feature = "view")]
79 #[must_use]
80 pub fn view(&self, color: ColorMode) -> crate::view::View {
81 crate::view::View::new(self.format, color).quiet(self.quiet)
82 }
83}