You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.2 KiB
35 lines
1.2 KiB
use clap::{Arg, Error, ErrorKind};
|
|
use clap_nested::{Command};
|
|
|
|
use crate::lib::m3u::{Playlist};
|
|
|
|
pub fn get_command<'a>() -> Command<'a, str>{
|
|
Command::new("dedupe")
|
|
.description("dedupe a m3u playlist")
|
|
.options(|app| {
|
|
app.arg(Arg::with_name("playlist")
|
|
.help("Path of the playlist(s) to de-duplicate")
|
|
.index(1)
|
|
.multiple(true)
|
|
.required(true)
|
|
)
|
|
})
|
|
.runner(| _args, matches| {
|
|
let dry_run = matches.is_present("dry-run");
|
|
match matches.values_of("playlist") {
|
|
Some(playlists) => {
|
|
for path in playlists {
|
|
let playlist = Playlist::read(path)?;
|
|
if ! dry_run {
|
|
playlist.write(path)?
|
|
} else {
|
|
println!("{:?}", playlist);
|
|
}
|
|
}
|
|
Ok(())
|
|
},
|
|
None => Err(
|
|
Error::with_description("playlist must be provided", ErrorKind::EmptyValue))
|
|
}
|
|
})
|
|
}
|