fix: handle multiple file arguments for show and edit
This commit is contained in:
+21
-20
@@ -10,11 +10,10 @@ use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::{fs::read_dir, fs::File, io::Read, process::Command};
|
||||
|
||||
pub fn edit(file_path: PathBuf, extra_files: [String; 8]) -> std::io::Result<()> {
|
||||
pub fn edit(file_path: Vec<PathBuf>, extra_files: [String; 8]) -> std::io::Result<()> {
|
||||
let tmp_file_path = PathBuf::from("/tmp/keks-sort-metadata");
|
||||
let mut tmp_file = File::create(&tmp_file_path)?;
|
||||
let editor = var("EDITOR").unwrap();
|
||||
let mut path: PathBuf = file_path.clone();
|
||||
let mut files = Vec::new();
|
||||
|
||||
struct FileMetadata {
|
||||
@@ -22,27 +21,29 @@ pub fn edit(file_path: PathBuf, extra_files: [String; 8]) -> std::io::Result<()>
|
||||
tag: Tag,
|
||||
}
|
||||
|
||||
if file_path.is_dir() {
|
||||
for music_file in read_dir(&file_path)? {
|
||||
path = music_file?.path();
|
||||
for file in &file_path {
|
||||
if file.is_dir() {
|
||||
for music_file in read_dir(file)? {
|
||||
let path = music_file?.path();
|
||||
|
||||
if path
|
||||
.extension()
|
||||
.and_then(|ext| ext.to_str())
|
||||
.is_some_and(|ext| extra_files.iter().any(|x| x == ext))
|
||||
{
|
||||
continue;
|
||||
if path
|
||||
.extension()
|
||||
.and_then(|ext| ext.to_str())
|
||||
.is_some_and(|ext| extra_files.iter().any(|x| x == ext))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
let tag = crate::get_metadata(&path);
|
||||
files.push(FileMetadata { path, tag });
|
||||
}
|
||||
|
||||
let tag = crate::get_metadata(&path);
|
||||
files.push(FileMetadata { path, tag });
|
||||
} else {
|
||||
let tag = &crate::get_metadata(file);
|
||||
files.push(FileMetadata {
|
||||
path: file.to_path_buf(),
|
||||
tag: tag.clone(),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
let tag = &crate::get_metadata(file_path);
|
||||
files.push(FileMetadata {
|
||||
path,
|
||||
tag: tag.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
for file in &files {
|
||||
|
||||
+10
-9
@@ -21,16 +21,15 @@ struct Args {
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
Import {
|
||||
#[arg(num_args = 1..)]
|
||||
files: Vec<PathBuf>,
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
copy: bool,
|
||||
},
|
||||
Show {
|
||||
file: PathBuf,
|
||||
files: Vec<PathBuf>,
|
||||
},
|
||||
Edit {
|
||||
files: PathBuf,
|
||||
files: Vec<PathBuf>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -70,17 +69,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
}
|
||||
|
||||
Commands::Show { file } => {
|
||||
println!("Show file: {:?}", file);
|
||||
let tag = get_metadata(file);
|
||||
Commands::Show { files } => {
|
||||
for file in files {
|
||||
println!("Show file: {:?}", file);
|
||||
let tag = get_metadata(file);
|
||||
|
||||
for item in tag.items() {
|
||||
println!("{:?}", item)
|
||||
for item in tag.items() {
|
||||
println!("{:?}", item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Commands::Edit { files } => {
|
||||
edit(files.to_path_buf(), extra_files)?;
|
||||
edit(files.to_vec(), extra_files)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user