feat: enforce output version v1 and add version subcommand

This commit is contained in:
2026-04-08 23:59:55 +08:00
parent a6daaff0fa
commit c4fa0eadcc
14 changed files with 117 additions and 10 deletions
+10 -1
View File
@@ -1,9 +1,18 @@
use crate::model::PrReviewDocument;
use crate::OUTPUT_VERSION;
pub fn render_json(doc: &PrReviewDocument) -> anyhow::Result<String> {
Ok(serde_json::to_string_pretty(doc)?)
}
pub fn parse_json(input: &str) -> anyhow::Result<PrReviewDocument> {
Ok(serde_json::from_str(input)?)
let doc: PrReviewDocument = serde_json::from_str(input)?;
if doc.version != OUTPUT_VERSION {
anyhow::bail!(
"unsupported document version: {}, expected {}",
doc.version,
OUTPUT_VERSION
);
}
Ok(doc)
}