1#![forbid(unsafe_code)]
2mod session;
5mod state_block;
6mod ingest;
7mod fs_safe;
8mod content_cache;
9
10pub use session::*;
11pub use state_block::*;
12pub use ingest::*;
13pub use fs_safe::*;
14pub use content_cache::*;
15
16#[derive(Debug, Clone, Copy, PartialEq, clap::ValueEnum)]
17pub enum OutputFormat {
18 Default,
19 Compact,
20 Json,
21}
22
23#[derive(Debug, Clone)]
24pub struct FormatConfig {
25 pub format: OutputFormat,
26 pub color: bool,
27}
28
29impl FormatConfig {
30 pub fn new(format: OutputFormat) -> Self {
31 Self { format, color: matches!(format, OutputFormat::Default) }
32 }
33
34 pub fn format_output(&self, label: &str, lines: &[String]) -> String {
35 match self.format {
36 OutputFormat::Json => {
37 serde_json::to_string(&lines).unwrap_or_default()
38 }
39 OutputFormat::Compact => lines.join("\n"),
40 OutputFormat::Default => {
41 if lines.is_empty() {
42 format!("{}: (none)", label)
43 } else {
44 format!("{}:\n {}", label, lines.join("\n "))
45 }
46 }
47 }
48 }
49}