MCPcopy Index your code
hub / github.com/PowerShell/DSC / get

Function get

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

Source from the content-addressed store, hash-verified

21use std::process::exit;
22
23pub fn get(dsc: &mut DscManager, resource_type: &FullyQualifiedTypeName, version: Option<&ResourceVersionReq>, input: &str, format: Option<&GetOutputFormat>) {
24 let Some(resource) = get_resource(dsc, resource_type, version) else {
25 error!("{}", DscError::ResourceNotFound(resource_type.to_string(), version.map_or(String::new(), |v| v.to_string())));
26 exit(EXIT_DSC_RESOURCE_NOT_FOUND);
27 };
28
29 debug!("{} {} {:?}", resource.type_name, t!("resource_command.implementedAs"), resource.implemented_as);
30 if resource.kind == Kind::Adapter {
31 error!("{}: {}", t!("resource_command.invalidOperationOnAdapter"), resource.type_name);
32 exit(EXIT_DSC_ERROR);
33 }
34
35 match resource.get(input) {
36 Ok(result) => {
37 if let GetResult::Resource(response) = &result
38 && format == Some(&GetOutputFormat::PassThrough) {
39 let json = match serde_json::to_string(&response.actual_state) {
40 Ok(json) => json,
41 Err(err) => {
42 error!("{}", t!("resource_command.jsonError", err = err));
43 exit(EXIT_JSON_ERROR);
44 }
45 };
46 write_object(&json, Some(&OutputFormat::Json), false);
47 return;
48 }
49
50 // convert to json
51 let json = match serde_json::to_string(&result) {
52 Ok(json) => json,
53 Err(err) => {
54 error!("{}", t!("resource_command.jsonError", err = err));
55 exit(EXIT_JSON_ERROR);
56 }
57 };
58 let format = match format {
59 Some(&GetOutputFormat::PrettyJson) => Some(&OutputFormat::PrettyJson),
60 Some(&GetOutputFormat::Yaml) => Some(&OutputFormat::Yaml),
61 None => None,
62 _ => Some(&OutputFormat::Json),
63 };
64 write_object(&json, format, false);
65 }
66 Err(err) => {
67 error!("{err}");
68 exit(EXIT_DSC_ERROR);
69 }
70 }
71}
72
73pub fn get_all(dsc: &mut DscManager, resource_type: &FullyQualifiedTypeName, version: Option<&ResourceVersionReq>, format: Option<&GetOutputFormat>) {
74 let input = String::new();

Callers 2

newMethod · 0.85
resourceFunction · 0.85

Calls 4

get_resourceFunction · 0.85
write_objectFunction · 0.85
to_stringFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected