Skip to content

Commit

Permalink
feat: add save command
Browse files Browse the repository at this point in the history
Relates to #16
  • Loading branch information
johnallen3d committed Sep 22, 2023
1 parent f95306a commit 29a01d6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Commands:
single Toggle single mode or set to provided state
consume Toggle consume mode or set to provided state
crossfade Toggle consume mode or set to provided state
save Save queue to a playlist
rm Remove a playlist
volume Set the volume to specified value <num> or increase/decrease it [+-]<num>
stats Provide mpd statistics
Expand Down
3 changes: 3 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ pub(crate) enum Commands {
#[command()]
Crossfade { seconds: Option<String> },

/// Save queue to a playlist
#[command()]
Save { name: String },
/// Remove a playlist
#[command()]
Rm { name: String },
Expand Down
8 changes: 8 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,14 @@ impl Client {
Ok(Some(response))
}

pub fn save(&mut self, name: &str) -> eyre::Result<Option<String>> {
self.client
.save(name)
.wrap_err(format!("Playlist already exists: {name}"))?;

Ok(None)
}

pub fn rm(&mut self, name: &str) -> eyre::Result<Option<String>> {
self.client
.pl_remove(name)
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fn main() {
Some(Commands::Consume { state }) => mpd.consume(state),
Some(Commands::Crossfade { seconds }) => mpd.crossfade(seconds),

Some(Commands::Save { name }) => mpd.save(&name),
Some(Commands::Rm { name }) => mpd.rm(&name),
Some(Commands::Volume { volume }) => mpd.set_volume(&volume),
Some(Commands::Stats) => mpd.stats(),
Expand Down

0 comments on commit 29a01d6

Please sign in to comment.