Skip to main content

clawless_cli/output/
output_mode.rs

1/// Output format and destination strategy
2///
3/// `OutputMode` controls where messages and results are written and how
4/// results are formatted. It is orthogonal to [`Verbosity`], which controls
5/// whether output is produced at all.
6///
7/// In text mode, all output goes to stdout. In JSON mode, messages go to
8/// stderr (keeping stdout reserved for machine-readable data) and results
9/// are serialized as JSON to stdout.
10///
11/// # Examples
12///
13/// ```
14/// use clawless_cli::output::OutputMode;
15///
16/// let mode = OutputMode::default();
17/// assert_eq!(mode, OutputMode::Text);
18/// ```
19///
20/// [`Verbosity`]: super::Verbosity
21#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
22pub enum OutputMode {
23    /// Human-readable text output; all output goes to stdout
24    #[default]
25    Text,
26    /// Machine-readable JSON output; messages go to stderr, results go to stdout as JSON
27    Json,
28}
29
30#[cfg(test)]
31mod tests {
32    // An assertion in a test panics by design. A `# Panics` section on every test
33    // would repeat that and give the reader no information.
34    #![allow(clippy::missing_panics_doc)]
35
36    use super::*;
37
38    #[test]
39    fn default_is_text() {
40        let mode = OutputMode::default();
41
42        assert_eq!(mode, OutputMode::Text);
43    }
44
45    #[test]
46    fn trait_send() {
47        fn assert_send<T: Send>() {}
48        assert_send::<OutputMode>();
49    }
50
51    #[test]
52    fn trait_sync() {
53        fn assert_sync<T: Sync>() {}
54        assert_sync::<OutputMode>();
55    }
56
57    #[test]
58    fn trait_unpin() {
59        fn assert_unpin<T: Unpin>() {}
60        assert_unpin::<OutputMode>();
61    }
62}