feat: add cli argument to specify whether to copy or move
This commit is contained in:
+11
-5
@@ -17,8 +17,14 @@ struct Args {
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
Import { file: PathBuf },
|
||||
Show { file: PathBuf },
|
||||
Import {
|
||||
file: PathBuf,
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
copy: bool,
|
||||
},
|
||||
Show {
|
||||
file: PathBuf,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -26,7 +32,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let extra_files = ["jpg", "png", "pdf", "log", "cue", "mp4", "lrc", "txt"].map(str::to_string);
|
||||
|
||||
match &args.command {
|
||||
Commands::Import { file } => {
|
||||
Commands::Import { file, copy } => {
|
||||
if file.is_dir() {
|
||||
println!("Importing folder: {:?}", file);
|
||||
for music_file in read_dir(file)? {
|
||||
@@ -39,12 +45,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
continue;
|
||||
}
|
||||
let tag = get_metadata(&path);
|
||||
let _ = move_files(path, tag.clone(), extra_files.clone());
|
||||
let _ = move_files(path, tag.clone(), extra_files.clone(), *copy);
|
||||
}
|
||||
} else {
|
||||
println!("Importing file: {:?}", file);
|
||||
let tag = get_metadata(file);
|
||||
let _ = move_files(file.clone(), tag.clone(), extra_files);
|
||||
let _ = move_files(file.clone(), tag.clone(), extra_files, *copy);
|
||||
}
|
||||
}
|
||||
Commands::Show { file } => {
|
||||
|
||||
Reference in New Issue
Block a user