11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
4- use crate :: args:: OutputFormat ;
4+ use crate :: args:: { GetOutputFormat , OutputFormat } ;
55use crate :: util:: { EXIT_DSC_ERROR , EXIT_INVALID_ARGS , EXIT_JSON_ERROR , EXIT_DSC_RESOURCE_NOT_FOUND , write_object} ;
66use dsc_lib:: configure:: config_doc:: { Configuration , ExecutionKind } ;
77use dsc_lib:: configure:: add_resource_export_results_to_configuration;
@@ -47,7 +47,7 @@ pub fn get(dsc: &DscManager, resource_type: &str, input: &str, format: Option<&O
4747 }
4848}
4949
50- pub fn get_all ( dsc : & DscManager , resource_type : & str , format : Option < & OutputFormat > ) {
50+ pub fn get_all ( dsc : & DscManager , resource_type : & str , format : Option < & GetOutputFormat > ) {
5151 let input = String :: new ( ) ;
5252 let Some ( resource) = get_resource ( dsc, resource_type) else {
5353 error ! ( "{}" , DscError :: ResourceNotFound ( resource_type. to_string( ) ) . to_string( ) ) ;
@@ -68,6 +68,18 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: Option<&OutputForm
6868 }
6969 } ;
7070
71+ if format == Some ( & GetOutputFormat :: JsonArray ) {
72+ let json = match serde_json:: to_string ( & export_result. actual_state ) {
73+ Ok ( json) => json,
74+ Err ( err) => {
75+ error ! ( "{}" , t!( "resource_command.jsonError" , err = err) ) ;
76+ exit ( EXIT_JSON_ERROR ) ;
77+ }
78+ } ;
79+ write_object ( & json, Some ( & OutputFormat :: Json ) , false ) ;
80+ return ;
81+ }
82+
7183 let mut include_separator = false ;
7284 for instance in export_result. actual_state
7385 {
@@ -78,10 +90,15 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: Option<&OutputForm
7890 let json = match serde_json:: to_string ( & get_result) {
7991 Ok ( json) => json,
8092 Err ( err) => {
81- error ! ( "JSON Error: {err}" ) ;
93+ error ! ( "{}" , t! ( "resource_command.jsonError" , err = err ) ) ;
8294 exit ( EXIT_JSON_ERROR ) ;
8395 }
8496 } ;
97+ let format = match format {
98+ Some ( & GetOutputFormat :: PrettyJson ) => Some ( & OutputFormat :: PrettyJson ) ,
99+ Some ( & GetOutputFormat :: Yaml ) => Some ( & OutputFormat :: Yaml ) ,
100+ _ => Some ( & OutputFormat :: Json ) ,
101+ } ;
85102 write_object ( & json, format, include_separator) ;
86103 include_separator = true ;
87104 }
0 commit comments