feat: enforce output version v1 and add version subcommand
This commit is contained in:
+10
-1
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user