#[arg(short = 's', long)]
skip_processed: bool,
+ /// Policy for which metadata should be updated
+ #[arg(long)]
+ file_update_policy: FileUpdatePolicy,
+
+ /// Policy for how changes should be made to the specified tags.
+ #[arg(long)]
+ tag_update_policy: TagUpdatePolicy,
+
/// Print information about which tags are written
#[arg(short = 'v', long)]
verbose: bool,
image_paths: Vec<PathBuf>,
}
-#[derive(Default, Clone, Serialize, Deserialize, ValueEnum)]
+#[derive(Default, Debug, Clone, Serialize, Deserialize, ValueEnum)]
enum TagUpdatePolicy {
- // Replace all existing contents (if any) with new items
+ /// Replace all existing contents (if any) with new items
Replace,
- // Append new items to existing tag contents
+ /// Append new items to existing tag contents
Append,
- // Remove existing items with the same prefix and then append new ones.
+ /// Remove existing items with the same prefix and then append new ones.
#[default]
ReplacePrefixed,
}
-#[derive(Default, Clone, Serialize, Deserialize, ValueEnum, PartialEq)]
+#[derive(Default, Debug, Clone, Serialize, Deserialize, ValueEnum, PartialEq)]
enum FileUpdatePolicy {
/// Just print the tags, do not update any files
DisplayOnly,
self.cli.as_ref().map(|c| c.skip_processed).unwrap_or(self.skip_processed)
}
+ fn tag_update_policy(&self) -> TagUpdatePolicy {
+ match &self.cli {
+ Some(c) => c.tag_update_policy.clone(),
+ _ => self.tag_update_policy.clone(),
+ }
+ }
+
+ fn file_update_policy(&self) -> FileUpdatePolicy {
+ match &self.cli {
+ Some(c) => c.file_update_policy.clone(),
+ _ => self.file_update_policy.clone(),
+ }
+ }
+
fn verbose(&self) -> bool {
self.cli.as_ref().map(|c| c.verbose).unwrap_or_default()
}
// Return path to XMP file if it exists and we're in a mode that
// updates it, None if we shouldn't update it, or error if it's
// required but missing.
- match config.file_update_policy {
+ match config.file_update_policy() {
FileUpdatePolicy::SidecarOnly | FileUpdatePolicy::SidecarAndImage => {
match xmp_path {
Some(_) => Ok(xmp_path),
}
fn should_update_image<P: AsRef<Path>>(config: &PwwConfig, filepath: P) -> Result<bool, PwwError> {
- match config.file_update_policy {
+ match config.file_update_policy() {
FileUpdatePolicy::ImageOnly | FileUpdatePolicy::SidecarAndImage => Ok(true),
FileUpdatePolicy::SidecarIfPresent => {
match xmp_file_path(&filepath) {
println!(" - updating file: {}", filepath.as_ref().to_string_lossy());
}
for metatag in metatags {
- let new_values: Vec<String> = match config.tag_update_policy {
+ let new_values: Vec<String> = match config.tag_update_policy() {
TagUpdatePolicy::Append => {
meta.get_tag_multiple_strings(&metatag).unwrap_or_default().into_iter().chain(tags.iter().cloned()).collect()
},
}
}
- if config.file_update_policy == FileUpdatePolicy::DisplayOnly {
+ if config.file_update_policy() == FileUpdatePolicy::DisplayOnly {
println!("{}", tags.join(", "));
}