Refactor repository property and publisher filtering in show_contents, improve clarity and efficiency by introducing section_filtered_properties and adding publisher-based property filtering logic. Update get_info to support publisher filtering.

This commit is contained in:
Till Wegmueller 2025-07-26 12:52:55 +02:00
parent 362042268a
commit f5b80a7d12
No known key found for this signature in database

View file

@ -370,8 +370,19 @@ fn main() -> Result<()> {
// For now, we're using FileBackend, which doesn't use these parameters // For now, we're using FileBackend, which doesn't use these parameters
let repo = FileBackend::open(repo_uri_or_path)?; let repo = FileBackend::open(repo_uri_or_path)?;
// Process the publisher parameter
let pub_names = if let Some(publishers) = publisher {
if !publishers.is_empty() {
publishers.clone()
} else {
Vec::new()
}
} else {
Vec::new()
};
// Filter properties if section_property is specified // Filter properties if section_property is specified
let filtered_properties = if let Some(section_props) = section_property { let section_filtered_properties = if let Some(section_props) = section_property {
let mut filtered = std::collections::HashMap::new(); let mut filtered = std::collections::HashMap::new();
for section_prop in section_props { for section_prop in section_props {
@ -397,6 +408,22 @@ fn main() -> Result<()> {
repo.config.properties.clone() repo.config.properties.clone()
}; };
// Filter properties by publisher if specified
let filtered_properties = if !pub_names.is_empty() {
let mut filtered = std::collections::HashMap::new();
for (key, value) in &section_filtered_properties {
let parts: Vec<&str> = key.split('/').collect();
if parts.len() == 2 && pub_names.contains(&parts[0].to_string()) {
filtered.insert(key.clone(), value.clone());
}
}
filtered
} else {
section_filtered_properties
};
// Determine the output format // Determine the output format
let output_format = format.as_deref().unwrap_or("table"); let output_format = format.as_deref().unwrap_or("table");
@ -460,8 +487,24 @@ fn main() -> Result<()> {
// For now, we're using FileBackend, which doesn't use these parameters // For now, we're using FileBackend, which doesn't use these parameters
let repo = FileBackend::open(repo_uri_or_path)?; let repo = FileBackend::open(repo_uri_or_path)?;
// Process the publisher parameter
let pub_names = if let Some(publishers) = publisher {
if !publishers.is_empty() {
publishers.clone()
} else {
Vec::new()
}
} else {
Vec::new()
};
// Get repository info // Get repository info
let repo_info = repo.get_info()?; let mut repo_info = repo.get_info()?;
// Filter publishers if specified
if !pub_names.is_empty() {
repo_info.publishers.retain(|p| pub_names.contains(&p.name));
}
// Determine the output format // Determine the output format
let output_format = format.as_deref().unwrap_or("table"); let output_format = format.as_deref().unwrap_or("table");