From 675ed3e3185bc815d6be557e7e8cba196fc74f14 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sat, 17 Oct 2020 13:36:50 +0300 Subject: [PATCH] Set a default for image filename when embedding --- src/bin/id3-image-embed.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/bin/id3-image-embed.rs b/src/bin/id3-image-embed.rs index cfe0724..87dc466 100644 --- a/src/bin/id3-image-embed.rs +++ b/src/bin/id3-image-embed.rs @@ -15,19 +15,22 @@ struct Opt { #[structopt(name = "music-file.mp3", required = true, parse(from_os_str))] music_filename: PathBuf, - /// Image file to embed - #[structopt(name = "image-file.jpg", required = true, parse(from_os_str))] - image_filename: PathBuf, + /// Image file to embed. If not given, will default to the music filename with a .jpg extension + #[structopt(name = "image-file.jpg", parse(from_os_str))] + image_filename: Option, } fn main() { let opt = Opt::from_args(); + let music_filename = opt.music_filename; + let image_filename = opt.image_filename. + unwrap_or_else(|| music_filename.with_extension("jpg")); - if let Err(e) = embed_image(&opt.music_filename, &opt.image_filename) { + if let Err(e) = embed_image(&music_filename, &image_filename) { eprintln!("{}", e); process::exit(1); } if opt.verbose >= 1 { - println!("Embedded {:?} into {:?}", opt.image_filename, opt.music_filename); + println!("Embedded {:?} into {:?}", image_filename, music_filename); } }