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)]
|
#[derive(Subcommand)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
Import { file: PathBuf },
|
Import {
|
||||||
Show { file: PathBuf },
|
file: PathBuf,
|
||||||
|
#[arg(short, long, default_value_t = false)]
|
||||||
|
copy: bool,
|
||||||
|
},
|
||||||
|
Show {
|
||||||
|
file: PathBuf,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
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);
|
let extra_files = ["jpg", "png", "pdf", "log", "cue", "mp4", "lrc", "txt"].map(str::to_string);
|
||||||
|
|
||||||
match &args.command {
|
match &args.command {
|
||||||
Commands::Import { file } => {
|
Commands::Import { file, copy } => {
|
||||||
if file.is_dir() {
|
if file.is_dir() {
|
||||||
println!("Importing folder: {:?}", file);
|
println!("Importing folder: {:?}", file);
|
||||||
for music_file in read_dir(file)? {
|
for music_file in read_dir(file)? {
|
||||||
@@ -39,12 +45,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let tag = get_metadata(&path);
|
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 {
|
} else {
|
||||||
println!("Importing file: {:?}", file);
|
println!("Importing file: {:?}", file);
|
||||||
let tag = get_metadata(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 } => {
|
Commands::Show { file } => {
|
||||||
|
|||||||
+1
-1
@@ -9,6 +9,7 @@ pub fn move_files(
|
|||||||
file_path: PathBuf,
|
file_path: PathBuf,
|
||||||
tag: Tag,
|
tag: Tag,
|
||||||
extra_files: [String; 8],
|
extra_files: [String; 8],
|
||||||
|
should_copy: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let target_dir = PathBuf::from("/home/user/Desktop/coding/keks-sort");
|
let target_dir = PathBuf::from("/home/user/Desktop/coding/keks-sort");
|
||||||
|
|
||||||
@@ -33,7 +34,6 @@ pub fn move_files(
|
|||||||
let _ = create_dir_all(dir_to_create);
|
let _ = create_dir_all(dir_to_create);
|
||||||
let target = target_dir.join(artist_dir).join(album_dir.as_ref());
|
let target = target_dir.join(artist_dir).join(album_dir.as_ref());
|
||||||
|
|
||||||
let should_copy = true;
|
|
||||||
if should_copy {
|
if should_copy {
|
||||||
copy(&file_path, target.join(file_path.file_name().unwrap()))?;
|
copy(&file_path, target.join(file_path.file_name().unwrap()))?;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user