Skip to main content

reliary_core/
lib.rs

1// reliary-core: CLI types, config, session state, output formatting
2mod session;
3mod state_block;
4mod ingest;
5use std::collections::HashMap;
6
7pub use session::*;
8pub use state_block::*;
9pub use ingest::*;
10
11#[derive(Debug, Clone)]
12pub struct Session {
13    pub turn_count: usize,
14    pub file_hashes: HashMap<String, u64>,
15}
16
17impl Default for Session {
18    fn default() -> Self {
19        Self::new()
20    }
21}
22
23impl Session {
24    pub fn new() -> Self {
25        Self { turn_count: 0, file_hashes: HashMap::new() }
26    }
27}
28
29#[derive(Debug, Clone, Copy, clap::ValueEnum)]
30pub enum OutputFormat {
31    Default,
32    Compact,
33    Json,
34}
35
36#[derive(Debug, Clone)]
37pub struct FormatConfig {
38    pub format: OutputFormat,
39    pub color: bool,
40}
41
42impl FormatConfig {
43    pub fn new(format: OutputFormat) -> Self {
44        Self { format, color: matches!(format, OutputFormat::Default) }
45    }
46
47    pub fn format_output(&self, label: &str, lines: &[String]) -> String {
48        match self.format {
49            OutputFormat::Json => {
50                serde_json::to_string(&lines).unwrap_or_default()
51            }
52            OutputFormat::Compact => lines.join("\n"),
53            OutputFormat::Default => {
54                if lines.is_empty() {
55                    format!("{}: (none)", label)
56                } else {
57                    format!("{}:\n  {}", label, lines.join("\n  "))
58                }
59            }
60        }
61    }
62}