feat: add render-md json input flow
This commit is contained in:
+24
@@ -1,9 +1,33 @@
|
||||
use std::path::Path;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
pub mod cli;
|
||||
pub mod error;
|
||||
pub mod model;
|
||||
pub mod output;
|
||||
pub mod render;
|
||||
|
||||
use crate::cli::{Cli, Commands, OutputFormat};
|
||||
use crate::output::write_output;
|
||||
use crate::render::json::{parse_json, render_json};
|
||||
use crate::render::markdown::render_markdown;
|
||||
|
||||
pub fn run() -> anyhow::Result<()> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
match cli.command {
|
||||
Commands::RenderMd(args) => {
|
||||
let raw = std::fs::read_to_string(&args.input)?;
|
||||
let doc = parse_json(&raw)?;
|
||||
let md = render_markdown(&doc);
|
||||
write_output(args.out.as_deref().map(Path::new), &md)?;
|
||||
}
|
||||
Commands::Fetch(_args) => {
|
||||
let _ = OutputFormat::Markdown;
|
||||
let _ = render_json;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
use crate::model::PrReviewDocument;
|
||||
|
||||
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)?)
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod json;
|
||||
pub mod markdown;
|
||||
|
||||
Reference in New Issue
Block a user