41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
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, bail};
|
|
use clap::Args as ClapArgs;
|
|
use serde_json::json;
|
|
|
|
use crate::client::{Client, index};
|
|
use crate::verbs::{print_json, rfc3339};
|
|
|
|
#[derive(ClapArgs)]
|
|
pub struct Args {
|
|
/// Comment id.
|
|
id: u64,
|
|
}
|
|
|
|
pub fn run(client: &Client, args: Args) -> Result<()> {
|
|
let (owner, name) = client.owner_repo()?;
|
|
let Some(c) = client
|
|
.api()
|
|
.issue_get_comment(owner, name, index(args.id)?)
|
|
.send()?
|
|
else {
|
|
bail!("hive-forge comment-show: comment {} not found", args.id);
|
|
};
|
|
if client.json_mode() {
|
|
let trimmed = json!({
|
|
"id": c.id,
|
|
"user": c.user.as_ref().and_then(|u| u.login.as_deref()),
|
|
"created_at": rfc3339(c.created_at),
|
|
"updated_at": rfc3339(c.updated_at),
|
|
"body": c.body,
|
|
"url": c.html_url,
|
|
});
|
|
print_json(&trimmed)
|
|
} else {
|
|
let body = c.body.as_deref().unwrap_or("");
|
|
println!("{body}");
|
|
Ok(())
|
|
}
|
|
}
|