@@ -24,6 +24,22 @@ fn display_content(option: &json::JsonValue, value: &json::JsonValue) {
2424 print ! ( "{value:width$}|" , value = content, width = width)
2525}
2626
27+ fn return_json ( option : & json:: JsonValue , value : & json:: JsonValue ) -> json:: JsonValue {
28+ if value. is_array ( ) {
29+ let mut contents = json:: JsonValue :: new_array ( ) ;
30+ let field = option[ "field" ] . as_str ( ) . unwrap_or ( "name" ) ;
31+ for entry in value. members ( ) {
32+ let _ = contents. push ( String :: from ( entry[ field] . as_str ( ) . unwrap_or ( "-" ) ) ) ;
33+ }
34+ contents
35+ } else if value. is_object ( ) {
36+ let field = option[ "field" ] . as_str ( ) . unwrap_or ( "name" ) ;
37+ value[ field] . clone ( )
38+ } else {
39+ value. clone ( )
40+ }
41+ }
42+
2743fn display_header ( option : & json:: JsonValue ) {
2844 print ! (
2945 "{title:width$}|" ,
@@ -83,6 +99,7 @@ fn form_jql(matches: &ArgMatches) -> String {
8399}
84100
85101pub fn list_issues ( matches : & ArgMatches ) {
102+ let show_json = matches. is_present ( "json" ) ;
86103 let jql = form_jql ( matches) ;
87104 let offset_result = matches. value_of ( "offset" ) . unwrap_or ( "0" ) . parse :: < u32 > ( ) ;
88105 if offset_result. is_err ( ) {
@@ -114,10 +131,7 @@ pub fn list_issues(matches: &ArgMatches) {
114131 ) ;
115132 }
116133 let issues = & search_response. unwrap ( ) [ "issues" ] ;
117- if !issues. is_array ( ) {
118- println ! ( "No issues found for the filter." ) ;
119- std:: process:: exit ( 0 ) ;
120- }
134+
121135 let display: String = String :: from (
122136 matches
123137 . value_of ( "display" )
@@ -138,6 +152,28 @@ pub fn list_issues(matches: &ArgMatches) {
138152 } ;
139153 let headers_to_display = display;
140154 let headers = headers_to_display. trim ( ) . split ( ',' ) ;
155+
156+ if show_json {
157+ let mut response = json:: JsonValue :: new_array ( ) ;
158+ for issue in issues. members ( ) {
159+ let mut data = json:: JsonValue :: new_object ( ) ;
160+ for header in headers. clone ( ) {
161+ if header == "key" {
162+ data[ header] = return_json ( & display_options[ header] , & issue[ header] ) ;
163+ } else {
164+ data[ header] = return_json ( & display_options[ header] , & issue[ "fields" ] [ header] ) ;
165+ }
166+ }
167+ let _ = response. push ( data) ;
168+ }
169+ println ! ( "{}" , response. pretty( 4 ) ) ;
170+ return ;
171+ }
172+
173+ if !issues. is_array ( ) {
174+ println ! ( "No issues found for the filter." ) ;
175+ std:: process:: exit ( 0 ) ;
176+ }
141177 let mut total = 0 ;
142178 for header in headers. clone ( ) {
143179 if display_options[ header] . is_null ( ) {
0 commit comments