(
dsc: &mut DscManager,
resource_name: &TypeNameFilter,
adapter_name: Option<&TypeNameFilter>,
description: Option<&String>,
tags: Option<&Vec<String>>,
format: Option<&ListOut
| 774 | } |
| 775 | |
| 776 | pub fn list_resources( |
| 777 | dsc: &mut DscManager, |
| 778 | resource_name: &TypeNameFilter, |
| 779 | adapter_name: Option<&TypeNameFilter>, |
| 780 | description: Option<&String>, |
| 781 | tags: Option<&Vec<String>>, |
| 782 | format: Option<&ListOutputFormat>, |
| 783 | progress_format: ProgressFormat |
| 784 | ) { |
| 785 | let mut write_table = false; |
| 786 | let mut table = Table::new(&[ |
| 787 | t!("subcommand.tableHeader_type").to_string().as_ref(), |
| 788 | t!("subcommand.tableHeader_kind").to_string().as_ref(), |
| 789 | t!("subcommand.tableHeader_version").to_string().as_ref(), |
| 790 | t!("subcommand.tableHeader_capabilities").to_string().as_ref(), |
| 791 | t!("subcommand.tableHeader_adapter").to_string().as_ref(), |
| 792 | t!("subcommand.tableHeader_description").to_string().as_ref(), |
| 793 | ]); |
| 794 | if format == Some(&ListOutputFormat::TableNoTruncate) || (format.is_none() && io::stdout().is_terminal()) { |
| 795 | // write as table if format is not specified and interactive |
| 796 | write_table = true; |
| 797 | } |
| 798 | let mut include_separator = false; |
| 799 | |
| 800 | for manifest_resource in dsc.list_available(&DiscoveryKind::Resource, resource_name, adapter_name, progress_format) { |
| 801 | if let ImportedManifest::Resource(resource) = manifest_resource { |
| 802 | let capability_types = [ |
| 803 | (Capability::Get, "g"), |
| 804 | (Capability::Set, "s"), |
| 805 | (Capability::SetHandlesExist, "x"), |
| 806 | (Capability::Test, "t"), |
| 807 | (Capability::Delete, "d"), |
| 808 | (Capability::Export, "e"), |
| 809 | (Capability::Resolve, "r"), |
| 810 | ]; |
| 811 | let mut capabilities = "-".repeat(capability_types.len()); |
| 812 | |
| 813 | for (i, (capability, letter)) in capability_types.iter().enumerate() { |
| 814 | if resource.capabilities.contains(capability) { |
| 815 | capabilities.replace_range(i..=i, letter); |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | // if description, tags, or write_table is specified, pull resource manifest if it exists |
| 820 | if let Some(ref manifest) = resource.manifest { |
| 821 | // if description is specified, skip if resource description does not contain it |
| 822 | if description.is_some() && (manifest.description.is_none() | !manifest.description.clone().unwrap_or_default().to_lowercase().contains(&description.unwrap_or(&String::new()).to_lowercase())) { |
| 823 | continue; |
| 824 | } |
| 825 | |
| 826 | // if tags is specified, skip if resource tags do not contain the tags |
| 827 | if let Some(tags) = tags { |
| 828 | if manifest.tags.is_empty() { continue; } |
| 829 | |
| 830 | let mut found = false; |
| 831 | for tag_to_find in tags { |
| 832 | for tag in manifest.tags.as_ref() { |
| 833 | if tag == tag_to_find { |
no test coverage detected