base_console/
output_format.rs1#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
6pub enum OutputFormat {
7 #[default]
9 Auto,
10 Text,
12 Json,
14}
15
16impl OutputFormat {
17 pub(crate) fn resolve(self, terminal: bool) -> Self {
18 match self {
19 Self::Auto if terminal => Self::Text,
20 Self::Auto => Self::Json,
21 format => format,
22 }
23 }
24}
25
26#[cfg(test)]
27mod tests {
28 use super::OutputFormat::*;
29
30 #[test]
31 fn automatic_selection_tracks_the_destination_and_explicit_formats_win() {
32 assert_eq!(Auto.resolve(true), Text);
33 assert_eq!(Auto.resolve(false), Json);
34 for terminal in [true, false] {
35 assert_eq!(Text.resolve(terminal), Text);
36 assert_eq!(Json.resolve(terminal), Json);
37 }
38 }
39}