Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/hive-forge/src/verbs/comment_show.rs

35 lines
1,009 B
Rust

//! `comment-show <id>` — print the body (or full JSON envelope
//! when `--json` is set globally) of a single comment by id.
use anyhow::Result;
use clap::Args as ClapArgs;
use serde_json::{Value, json};
use crate::client::Client;
use crate::verbs::print_json;
#[derive(ClapArgs)]
pub struct Args {
/// Comment id.
id: u64,
}
pub fn run(client: &Client, args: Args) -> Result<()> {
let repo = client.repo();
let v = client.get_json(&format!("/repos/{repo}/issues/comments/{}", args.id))?;
if client.json_mode() {
let trimmed = json!({
"id": v.get("id"),
"user": v.get("user").and_then(|u| u.get("login")),
"created_at": v.get("created_at"),
"updated_at": v.get("updated_at"),
"body": v.get("body"),
"url": v.get("html_url"),
});
print_json(&trimmed)
} else {
let body = v.get("body").and_then(Value::as_str).unwrap_or("");
println!("{body}");
Ok(())
}
}