feat: add new subcommand to open default editor with metadata
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
use lofty::tag::Tag;
|
||||
use std::env::var;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::{fs::File, io::Read, process::Command};
|
||||
|
||||
pub fn edit(file_path: PathBuf, tag: Tag) -> std::io::Result<()> {
|
||||
let editor = var("EDITOR").unwrap();
|
||||
let mut file = File::create(&file_path)?;
|
||||
for item in tag.items() {
|
||||
writeln!(
|
||||
file,
|
||||
"{:?} = {:?}",
|
||||
item.key(),
|
||||
item.value().text().unwrap_or("")
|
||||
)?;
|
||||
}
|
||||
|
||||
Command::new(editor)
|
||||
.arg(&file_path)
|
||||
.status()
|
||||
.expect("Something went wrong");
|
||||
|
||||
let mut editable = String::new();
|
||||
let _ = File::open(file_path)
|
||||
.expect("Could not open file")
|
||||
.read_to_string(&mut editable);
|
||||
|
||||
println!("File content:\n{}", editable);
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user