MCPcopy Create free account
hub / github.com/PowerShell/DSC / get_all

Function get_all

dsc/src/resource_command.rs:73–129  ·  view source on GitHub ↗
(dsc: &mut DscManager, resource_type: &FullyQualifiedTypeName, version: Option<&ResourceVersionReq>, format: Option<&GetOutputFormat>)

Source from the content-addressed store, hash-verified

71}
72
73pub fn get_all(dsc: &mut DscManager, resource_type: &FullyQualifiedTypeName, version: Option<&ResourceVersionReq>, format: Option<&GetOutputFormat>) {
74 let input = String::new();
75 let Some(resource) = get_resource(dsc, resource_type, version) else {
76 error!("{}", DscError::ResourceNotFound(resource_type.to_string(), version.map_or(String::new(), |r| r.to_string())));
77 exit(EXIT_DSC_RESOURCE_NOT_FOUND);
78 };
79
80 debug!("{} {} {:?}", resource.type_name, t!("resource_command.implementedAs"), resource.implemented_as);
81 if resource.kind == Kind::Adapter {
82 error!("{}: {}", t!("resource_command.invalidOperationOnAdapter"), resource.type_name);
83 exit(EXIT_DSC_ERROR);
84 }
85
86 let export_result = match resource.export(&input) {
87 Ok(export) => { export }
88 Err(err) => {
89 error!("{err}");
90 exit(EXIT_DSC_ERROR);
91 }
92 };
93
94 if format == Some(&GetOutputFormat::JsonArray) {
95 let json = match serde_json::to_string(&export_result.actual_state) {
96 Ok(json) => json,
97 Err(err) => {
98 error!("{}", t!("resource_command.jsonError", err = err));
99 exit(EXIT_JSON_ERROR);
100 }
101 };
102 write_object(&json, Some(&OutputFormat::Json), false);
103 return;
104 }
105
106 let mut include_separator = false;
107 for instance in export_result.actual_state
108 {
109 let get_result = GetResult::Resource(ResourceGetResponse {
110 actual_state: instance.clone(),
111 });
112
113 let json = match serde_json::to_string(&get_result) {
114 Ok(json) => json,
115 Err(err) => {
116 error!("{}", t!("resource_command.jsonError", err = err));
117 exit(EXIT_JSON_ERROR);
118 }
119 };
120 let format = match format {
121 Some(&GetOutputFormat::PrettyJson) => Some(&OutputFormat::PrettyJson),
122 Some(&GetOutputFormat::Yaml) => Some(&OutputFormat::Yaml),
123 None => None,
124 _ => Some(&OutputFormat::Json),
125 };
126 write_object(&json, format, include_separator);
127 include_separator = true;
128 }
129}
130

Callers 1

resourceFunction · 0.85

Calls 6

get_resourceFunction · 0.85
write_objectFunction · 0.85
exportMethod · 0.80
newFunction · 0.50
to_stringFunction · 0.50
ResourceClass · 0.50

Tested by

no test coverage detected