(dsc: &mut DscManager, extension_name: &TypeNameFilter, format: Option<&ListOutputFormat>, progress_format: ProgressFormat)
| 616 | } |
| 617 | |
| 618 | fn list_extensions(dsc: &mut DscManager, extension_name: &TypeNameFilter, format: Option<&ListOutputFormat>, progress_format: ProgressFormat) { |
| 619 | let mut write_table = false; |
| 620 | let mut table = Table::new(&[ |
| 621 | t!("subcommand.tableHeader_type").to_string().as_ref(), |
| 622 | t!("subcommand.tableHeader_version").to_string().as_ref(), |
| 623 | t!("subcommand.tableHeader_capabilities").to_string().as_ref(), |
| 624 | t!("subcommand.tableHeader_description").to_string().as_ref(), |
| 625 | ]); |
| 626 | if format.is_none() && io::stdout().is_terminal() { |
| 627 | // write as table if format is not specified and interactive |
| 628 | write_table = true; |
| 629 | } |
| 630 | let mut include_separator = false; |
| 631 | |
| 632 | for manifest_resource in dsc.list_available(&DiscoveryKind::Extension, extension_name, None, progress_format) { |
| 633 | if let ImportedManifest::Extension(extension) = manifest_resource { |
| 634 | let capability_types = [ |
| 635 | (ExtensionCapability::Discover, "d"), |
| 636 | (ExtensionCapability::Secret, "s"), |
| 637 | (ExtensionCapability::Import, "i"), |
| 638 | ]; |
| 639 | let mut capabilities = "-".repeat(capability_types.len()); |
| 640 | |
| 641 | for (i, (capability, letter)) in capability_types.iter().enumerate() { |
| 642 | if extension.capabilities.contains(capability) { |
| 643 | capabilities.replace_range(i..=i, letter); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | if write_table { |
| 648 | table.add_row(vec![ |
| 649 | extension.type_name.to_string(), |
| 650 | extension.version.to_string(), |
| 651 | capabilities, |
| 652 | extension.description.unwrap_or_default() |
| 653 | ]); |
| 654 | } |
| 655 | else { |
| 656 | // convert to json |
| 657 | let json = match serde_json::to_string(&extension) { |
| 658 | Ok(json) => json, |
| 659 | Err(err) => { |
| 660 | error!("JSON: {err}"); |
| 661 | exit(EXIT_JSON_ERROR); |
| 662 | } |
| 663 | }; |
| 664 | let format = match format { |
| 665 | Some(ListOutputFormat::Json) => Some(OutputFormat::Json), |
| 666 | Some(ListOutputFormat::PrettyJson) => Some(OutputFormat::PrettyJson), |
| 667 | Some(ListOutputFormat::Yaml) => Some(OutputFormat::Yaml), |
| 668 | _ => None, |
| 669 | }; |
| 670 | write_object(&json, format.as_ref(), include_separator); |
| 671 | include_separator = true; |
| 672 | // insert newline separating instances if writing to console |
| 673 | if io::stdout().is_terminal() { println!(); } |
| 674 | } |
| 675 | } |
no test coverage detected