Initial upload: GitPulse - Developer Productivity Analyzer CLI tool
This commit is contained in:
34
src/export/json.rs
Normal file
34
src/export/json.rs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
use crate::models::AnalysisResult;
|
||||||
|
use anyhow::{Context, Result};
|
||||||
|
use serde_json;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub fn export_json(result: &AnalysisResult, output: Option<PathBuf>) -> Result<()> {
|
||||||
|
let json = serde_json::to_string_pretty(result)
|
||||||
|
.context("Failed to serialize to JSON")?;
|
||||||
|
|
||||||
|
if let Some(path) = output {
|
||||||
|
let mut file = File::create(&path).context("Failed to create output file")?;
|
||||||
|
file.write_all(json.as_bytes())
|
||||||
|
.context("Failed to write to output file")?;
|
||||||
|
} else {
|
||||||
|
println!("{}", json);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn export_json_compact(result: &AnalysisResult, output: Option<PathBuf>) -> Result<()> {
|
||||||
|
let json = serde_json::to_string(result)
|
||||||
|
.context("Failed to serialize to JSON")?;
|
||||||
|
|
||||||
|
if let Some(path) = output {
|
||||||
|
let mut file = File::create(&path).context("Failed to create output file")?;
|
||||||
|
file.write_all(json.as_bytes())
|
||||||
|
.context("Failed to write to output file")?;
|
||||||
|
} else {
|
||||||
|
println!("{}", json);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user