Skip to main content

om_context/output/
mod.rs

1pub mod json;
2pub mod xml;
3
4use serde::Serialize;
5use std::str::FromStr;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum OutputFormat {
9    Text,
10    Json,
11    Xml,
12}
13
14impl FromStr for OutputFormat {
15    type Err = String;
16
17    fn from_str(s: &str) -> Result<Self, Self::Err> {
18        match s.to_lowercase().as_str() {
19            "text" => Ok(OutputFormat::Text),
20            "json" => Ok(OutputFormat::Json),
21            "xml" => Ok(OutputFormat::Xml),
22            _ => Err(format!("Invalid format: {}. Use text, json, or xml", s)),
23        }
24    }
25}
26
27#[derive(Serialize, Debug, Clone)]
28pub struct FileOutput {
29    pub path: String,
30    pub score: i32,
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub tokens: Option<usize>,
33    pub lines: usize,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub content: Option<String>,
36}
37
38#[derive(Serialize, Debug)]
39pub struct TreeOutput {
40    pub project: String,
41    pub files: Vec<FileOutput>,
42}
43
44#[derive(Serialize, Debug)]
45pub struct CatOutput {
46    pub project: String,
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub session: Option<String>,
49    pub files_shown: usize,
50    pub skipped_binary: usize,
51    pub skipped_session: usize,
52    pub total_lines: usize,
53    pub files: Vec<FileOutput>,
54}