feat: Update Add command to use --tag flag and sort tags alphabetically
This commit is contained in:
parent
9031ec9af1
commit
64d3761de9
2 changed files with 21 additions and 9 deletions
|
|
@ -38,10 +38,9 @@ enum Commands {
|
|||
/// Add tags to files
|
||||
Add {
|
||||
/// Tags to add
|
||||
#[arg(required = true)]
|
||||
#[arg(long = "tag", required = true)]
|
||||
tags: Vec<String>,
|
||||
/// Files to process
|
||||
#[arg(required = true)]
|
||||
files: Vec<String>,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,13 +65,26 @@ pub fn parse_tags(filename: &str) -> Result<(String, Vec<String>, String), Parse
|
|||
}
|
||||
}
|
||||
|
||||
let mut unique_tags = std::collections::HashSet::new();
|
||||
for tag in tag_part.split_whitespace() {
|
||||
validate_tag(tag)?;
|
||||
unique_tags.insert(tag.to_string());
|
||||
}
|
||||
|
||||
unique_tags.into_iter().collect()
|
||||
// First parse all tags
|
||||
let parsed_tags: Vec<String> = tag_part
|
||||
.split_whitespace()
|
||||
.map(|tag| {
|
||||
validate_tag(tag)?;
|
||||
Ok(tag.to_string())
|
||||
})
|
||||
.collect::<Result<_, TagError>>()?;
|
||||
|
||||
// Then filter duplicates using a HashSet
|
||||
let unique_tags: Vec<String> = parsed_tags
|
||||
.into_iter()
|
||||
.collect::<std::collections::HashSet<_>>()
|
||||
.into_iter()
|
||||
.collect();
|
||||
|
||||
// Finally sort
|
||||
let mut tags = unique_tags;
|
||||
tags.sort();
|
||||
tags
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue