mirror of
https://codeberg.org/Toasterson/ips.git
synced 2026-04-10 21:30:41 +00:00
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:
parent
362042268a
commit
f5b80a7d12
1 changed files with 45 additions and 2 deletions
|
|
@ -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 §ion_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");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue