@@ -26,6 +26,7 @@ export function listCommand(): Command {
2626 . option ( '--field <name=value...>' , 'Filter by custom field (can specify multiple)' )
2727 . option ( '--sort <field>' , 'Sort by field (id, created, name, status, priority)' , 'id' )
2828 . option ( '--order <order>' , 'Sort order (asc, desc)' , 'desc' )
29+ . option ( '--json' , 'Output as JSON' )
2930 . action ( async ( options : {
3031 archived ?: boolean ;
3132 status ?: SpecStatus ;
@@ -35,6 +36,7 @@ export function listCommand(): Command {
3536 field ?: string [ ] ;
3637 sort ?: string ;
3738 order ?: string ;
39+ json ?: boolean ;
3840 } ) => {
3941 const customFields = parseCustomFieldOptions ( options . field ) ;
4042 const listOptions : {
@@ -46,6 +48,7 @@ export function listCommand(): Command {
4648 customFields ?: Record < string , unknown > ;
4749 sortBy ?: string ;
4850 sortOrder ?: 'asc' | 'desc' ;
51+ json ?: boolean ;
4952 } = {
5053 showArchived : options . archived ,
5154 status : options . status ,
@@ -55,6 +58,7 @@ export function listCommand(): Command {
5558 customFields : Object . keys ( customFields ) . length > 0 ? customFields : undefined ,
5659 sortBy : options . sort || 'id' ,
5760 sortOrder : ( options . order as 'asc' | 'desc' ) || 'desc' ,
61+ json : options . json ,
5862 } ;
5963 await listSpecs ( listOptions ) ;
6064 } ) ;
@@ -69,6 +73,7 @@ export async function listSpecs(options: {
6973 customFields ?: Record < string , unknown > ;
7074 sortBy ?: string ;
7175 sortOrder ?: 'asc' | 'desc' ;
76+ json ?: boolean ;
7277} = { } ) : Promise < void > {
7378 // Auto-check for conflicts before listing
7479 await autoCheckIfEnabled ( ) ;
@@ -106,7 +111,32 @@ export async function listSpecs(options: {
106111 ) ;
107112
108113 if ( specs . length === 0 ) {
109- console . log ( chalk . dim ( 'No specs found.' ) ) ;
114+ if ( options . json ) {
115+ console . log ( JSON . stringify ( { specs : [ ] , total : 0 } , null , 2 ) ) ;
116+ } else {
117+ console . log ( chalk . dim ( 'No specs found.' ) ) ;
118+ }
119+ return ;
120+ }
121+
122+ // JSON output
123+ if ( options . json ) {
124+ const jsonOutput = {
125+ specs : specs . map ( spec => ( {
126+ path : spec . path ,
127+ name : spec . name ,
128+ status : spec . frontmatter . status ,
129+ priority : spec . frontmatter . priority ,
130+ tags : spec . frontmatter . tags ,
131+ assignee : spec . frontmatter . assignee ,
132+ created : spec . frontmatter . created ,
133+ completed : spec . frontmatter . completed ,
134+ subFiles : spec . subFiles ?. length || 0 ,
135+ } ) ) ,
136+ total : specs . length ,
137+ filter : options ,
138+ } ;
139+ console . log ( JSON . stringify ( jsonOutput , null , 2 ) ) ;
110140 return ;
111141 }
112142
0 commit comments