diff --git a/dsc/src/subcommand.rs b/dsc/src/subcommand.rs index d08a56a27..9145384fb 100644 --- a/dsc/src/subcommand.rs +++ b/dsc/src/subcommand.rs @@ -322,14 +322,15 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { ResourceSubCommand::List { resource_name, description, tags, format } => { let mut write_table = false; - let mut table = Table::new(&["Type", "Version", "Requires", "Description"]); + let mut methods: Vec = Vec::new(); + let mut table = Table::new(&["Type", "Version", "Methods", "Requires", "Description"]); if format.is_none() && atty::is(Stream::Stdout) { - // write as table if fornat is not specified and interactive + // write as table if format is not specified and interactive write_table = true; } for resource in dsc.list_available_resources(&resource_name.clone().unwrap_or_default()) { - // if description is specified, skip if resource description does not contain it - if description.is_some() || tags.is_some() { + // if description, tags, or write_table is specified, pull resource manifest if it exists + if description.is_some() || tags.is_some() || write_table { let Some(ref resource_manifest) = resource.manifest else { continue; }; @@ -341,6 +342,7 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { } }; + // if description is specified, skip if resource description does not contain it if description.is_some() && (manifest.description.is_none() | !manifest.description.unwrap_or_default().to_lowercase().contains(&description.as_ref().unwrap_or(&String::new()).to_lowercase())) { continue; @@ -348,9 +350,7 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { // if tags is specified, skip if resource tags do not contain the tags if let Some(tags) = tags { - let Some(manifest_tags) = manifest.tags else { - continue; - }; + let Some(manifest_tags) = manifest.tags else { continue; }; let mut found = false; for tag_to_find in tags { @@ -361,16 +361,20 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { } } } - if !found { - continue; - } + if !found { continue; } } + + methods = vec!["get".to_string()]; + if manifest.set.is_some() { methods.push("set".to_string()); } + if manifest.test.is_some() { methods.push("test".to_string()); } + if manifest.export.is_some() { methods.push("export".to_string()); } } if write_table { table.add_row(vec![ resource.type_name, resource.version, + methods.join(", "), resource.requires.unwrap_or_default(), resource.description.unwrap_or_default() ]); @@ -386,9 +390,7 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { }; write_output(&json, format); // insert newline separating instances if writing to console - if atty::is(Stream::Stdout) { - println!(); - } + if atty::is(Stream::Stdout) { println!(); } } } diff --git a/dsc_lib/src/configure/mod.rs b/dsc_lib/src/configure/mod.rs index 19871df55..6e953958d 100644 --- a/dsc_lib/src/configure/mod.rs +++ b/dsc_lib/src/configure/mod.rs @@ -45,13 +45,13 @@ pub enum ErrorAction { /// /// # Panics /// -/// Doesn't panic because there is a match/Some check before unwrap(); false positive. +/// Doesn't panic because there is a match/Some check before `unwrap()`; false positive. /// /// # Errors /// /// This function will return an error if the underlying resource fails. pub fn add_resource_export_results_to_configuration(resource: &DscResource, provider_resource: Option<&DscResource>, conf: &mut Configuration, input: &str) -> Result<(), DscError> { - + let export_result = match provider_resource { Some(_) => provider_resource.unwrap().export(input)?, _ => resource.export(input)?