@@ -90,6 +90,24 @@ function getConfig(opts: CliOptions): ConfigResult {
9090return { apiKey} ;
9191}
9292
93+ // Human-friendly output helper: YAML for TTY by default, JSON when --json or non-TTY
94+ function printResult ( result :unknown , json ?:boolean ) :void {
95+ if ( typeof result === "string" ) {
96+ process . stdout . write ( result ) ;
97+ if ( ! / \n $ / . test ( result ) ) console . log ( ) ;
98+ return ;
99+ }
100+ if ( json || ! process . stdout . isTTY ) {
101+ console . log ( JSON . stringify ( result , null , 2 ) ) ;
102+ } else {
103+ let text= yaml . dump ( result as any ) ;
104+ if ( Array . isArray ( result ) ) {
105+ text= text . replace ( / \n - / g, "\n\n- " ) ;
106+ }
107+ console . log ( text ) ;
108+ }
109+ }
110+
93111const program= new Command ( ) ;
94112
95113program
@@ -1192,7 +1210,8 @@ issues
11921210. command ( "list" )
11931211. description ( "list issues" )
11941212. option ( "--debug" , "enable debug output" )
1195- . action ( async ( opts :{ debug ?:boolean } ) => {
1213+ . option ( "--json" , "output raw JSON" )
1214+ . action ( async ( opts :{ debug ?:boolean ; json ?:boolean } ) => {
11961215try {
11971216const rootOpts = program . opts < CliOptions > ( ) ;
11981217const cfg = config . readConfig ( ) ;
@@ -1206,12 +1225,7 @@ issues
12061225const { apiBaseUrl} = resolveBaseUrls ( rootOpts , cfg ) ;
12071226
12081227const result = await fetchIssues ( { apiKey, apiBaseUrl, debug :! ! opts . debug } ) ;
1209- if ( typeof result === "string" ) {
1210- process . stdout . write ( result ) ;
1211- if ( ! / \n $ / . test ( result ) ) console . log ( ) ;
1212- } else {
1213- console . log ( JSON . stringify ( result , null , 2 ) ) ;
1214- }
1228+ printResult ( result , opts . json ) ;
12151229} catch ( err ) {
12161230const message = err instanceof Error ?err . message :String ( err ) ;
12171231console . error ( message ) ;
@@ -1223,7 +1237,8 @@ issues
12231237. command ( "comments <issueId>" )
12241238. description ( "list comments for an issue" )
12251239. option ( "--debug" , "enable debug output" )
1226- . action ( async ( issueId :string , opts :{ debug ?:boolean } ) => {
1240+ . option ( "--json" , "output raw JSON" )
1241+ . action ( async ( issueId :string , opts :{ debug ?:boolean ; json ?:boolean } ) => {
12271242try {
12281243const rootOpts = program . opts < CliOptions > ( ) ;
12291244const cfg = config . readConfig ( ) ;
@@ -1237,12 +1252,7 @@ issues
12371252const { apiBaseUrl} = resolveBaseUrls ( rootOpts , cfg ) ;
12381253
12391254const result = await fetchIssueComments ( { apiKey, apiBaseUrl, issueId, debug :! ! opts . debug } ) ;
1240- if ( typeof result === "string" ) {
1241- process . stdout . write ( result ) ;
1242- if ( ! / \n $ / . test ( result ) ) console . log ( ) ;
1243- } else {
1244- console . log ( JSON . stringify ( result , null , 2 ) ) ;
1245- }
1255+ printResult ( result , opts . json ) ;
12461256} catch ( err ) {
12471257const message = err instanceof Error ?err . message :String ( err ) ;
12481258console . error ( message ) ;
@@ -1255,7 +1265,8 @@ issues
12551265. description ( "post a new comment to an issue" )
12561266. option ( "--parent <uuid>" , "parent comment id" )
12571267. option ( "--debug" , "enable debug output" )
1258- . action ( async ( issueId :string , content :string , opts :{ parent ?:string ; debug ?:boolean } ) => {
1268+ . option ( "--json" , "output raw JSON" )
1269+ . action ( async ( issueId :string , content :string , opts :{ parent ?:string ; debug ?:boolean ; json ?:boolean } ) => {
12591270try {
12601271// Interpret escape sequences in content (e.g., \n -> newline)
12611272if ( opts . debug ) {
@@ -1287,12 +1298,7 @@ issues
12871298parentCommentId :opts . parent ,
12881299debug :! ! opts . debug ,
12891300} ) ;
1290- if ( typeof result === "string" ) {
1291- process . stdout . write ( result ) ;
1292- if ( ! / \n $ / . test ( result ) ) console . log ( ) ;
1293- } else {
1294- console . log ( JSON . stringify ( result , null , 2 ) ) ;
1295- }
1301+ printResult ( result , opts . json ) ;
12961302} catch ( err ) {
12971303const message = err instanceof Error ?err . message :String ( err ) ;
12981304console . error ( message ) ;