hive-forge: make --json a global flag (closes #421)
This commit is contained in:
parent
3cd9240594
commit
d0a1ee037b
5 changed files with 33 additions and 16 deletions
|
|
@ -1,5 +1,5 @@
|
|||
//! `comment-show <id> [--json] [repo]` — print the body (or full
|
||||
//! JSON) of a single comment by id.
|
||||
//! `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;
|
||||
|
|
@ -12,15 +12,12 @@ use crate::verbs::print_json;
|
|||
pub struct Args {
|
||||
/// Comment id.
|
||||
id: u64,
|
||||
/// Print full JSON envelope instead of just the body text.
|
||||
#[arg(long)]
|
||||
json: bool,
|
||||
}
|
||||
|
||||
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 args.json {
|
||||
if client.json_mode() {
|
||||
let trimmed = json!({
|
||||
"id": v.get("id"),
|
||||
"user": v.get("user").and_then(|u| u.get("login")),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
//! `comments <number> [--json] [--limit N]` — list all comments on
|
||||
//! an issue or PR. Closes the curl-fallback gap (#418).
|
||||
//! `comments <number> [--limit N]` — list all comments on an issue
|
||||
//! or PR. Closes the curl-fallback gap (#418). Use the global
|
||||
//! `--json` flag for JSON output (#421).
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Args as ClapArgs;
|
||||
|
|
@ -12,9 +13,6 @@ use crate::verbs::print_json;
|
|||
pub struct Args {
|
||||
/// Issue or PR number.
|
||||
number: u64,
|
||||
/// Print as JSON array instead of human-readable markdown.
|
||||
#[arg(long)]
|
||||
json: bool,
|
||||
/// Page size (Forgejo caps at 50 by default).
|
||||
#[arg(long, default_value_t = 50)]
|
||||
limit: u64,
|
||||
|
|
@ -26,7 +24,7 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
|
|||
"/repos/{repo}/issues/{}/comments?limit={}",
|
||||
args.number, args.limit
|
||||
))?;
|
||||
if args.json {
|
||||
if client.json_mode() {
|
||||
let trimmed: Vec<Value> = v
|
||||
.as_array()
|
||||
.map(|a| {
|
||||
|
|
|
|||
Loading…
Reference in a new issue