1use clap::Args;
2
3use crate::color::ColorMode;
4use crate::flags::resolve_color;
5use crate::format::OutputFormat;
6
7#[cfg_attr(
14 feature = "view",
15 doc = "",
16 doc = "[`Self::view`]: Self::view",
17 doc = "[`View`]: crate::view::View"
18)]
19#[cfg_attr(
20 not(feature = "view"),
21 doc = "",
22 doc = "[`Self::view`]: crate#cargo-features",
23 doc = "[`View`]: crate#cargo-features"
24)]
25#[derive(Args, Clone, Debug, Default, Eq, PartialEq)]
30#[command(about = None, long_about = None)]
31#[non_exhaustive]
32pub struct OutputArgs {
33 #[arg(
35 short = 'f',
36 long,
37 global = true,
38 value_enum,
39 default_value = "pretty",
40 help_heading = "Output"
41 )]
42 pub format: OutputFormat,
43 #[arg(
45 short = 'c',
46 long,
47 global = true,
48 value_enum,
49 default_value = "auto",
50 help_heading = "Output"
51 )]
52 color: ColorMode,
53 #[arg(long, global = true, help_heading = "Output")]
55 no_color: bool,
56 #[arg(short = 'q', long, global = true, help_heading = "Output")]
58 pub quiet: bool,
59}
60
61impl OutputArgs {
62 #[must_use]
65 pub fn color(&self) -> ColorMode {
66 resolve_color(self.color, self.no_color)
67 }
68
69 #[cfg(feature = "view")]
72 #[must_use]
73 pub fn view(&self) -> crate::view::View {
74 crate::view::View::new(self.format, self.color()).quiet(self.quiet)
75 }
76}
77
78#[cfg_attr(feature = "view", doc = "", doc = "[`Self::view`]: Self::view")]
83#[cfg_attr(
84 not(feature = "view"),
85 doc = "",
86 doc = "[`Self::view`]: crate#cargo-features"
87)]
88#[derive(Args, Clone, Debug, Default, Eq, PartialEq)]
91#[command(about = None, long_about = None)]
92#[non_exhaustive]
93pub struct FormatArgs {
94 #[arg(
96 short = 'f',
97 long,
98 global = true,
99 value_enum,
100 default_value = "pretty",
101 help_heading = "Output"
102 )]
103 pub format: OutputFormat,
104 #[arg(short = 'q', long, global = true, help_heading = "Output")]
106 pub quiet: bool,
107}
108
109impl FormatArgs {
110 #[cfg(feature = "view")]
113 #[must_use]
114 pub fn view(&self, color: ColorMode) -> crate::view::View {
115 crate::view::View::new(self.format, color).quiet(self.quiet)
116 }
117}
118
119#[derive(Args, Clone, Debug, Default, Eq, PartialEq)]
124#[command(about = None, long_about = None)]
125#[non_exhaustive]
126pub struct FormatLong {
127 #[arg(
129 long,
130 global = true,
131 value_enum,
132 default_value = "pretty",
133 help_heading = "Output"
134 )]
135 pub format: OutputFormat,
136 #[arg(short = 'q', long, global = true, help_heading = "Output")]
138 pub quiet: bool,
139}
140
141impl FormatLong {
142 #[cfg(feature = "view")]
145 #[must_use]
146 pub fn view(&self, color: ColorMode) -> crate::view::View {
147 crate::view::View::new(self.format, color).quiet(self.quiet)
148 }
149}