diff --git a/doc/index.rst b/doc/index.rst index 729a367..106e156 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -84,6 +84,10 @@ Options Wait for operation to finish (e.g. database update). +.. option:: -F, --force + + Force certain operations (e.g. overwriting playlist while saving). + .. option:: --range=[START]:[END] Operate on a range (e.g. when loading a playlist). START is the @@ -250,7 +254,8 @@ Playlist Commands :command:`rm ` - Deletes a specific playlist. -:command:`save ` - Saves playlist as . +:command:`save [--force] ` - Saves playlist as . With + :option:`--force`, overwrites the playlist if it already exists. :command:`addplaylist ` - Adds a song from the music database to the playlist. The playlist will be created if it does not exist. diff --git a/src/command.c b/src/command.c index 7fdfe95..e329d80 100644 --- a/src/command.c +++ b/src/command.c @@ -28,7 +28,6 @@ SIMPLE_CMD(cmd_prev, mpd_run_previous, 1) SIMPLE_CMD(cmd_stop, mpd_run_stop, 1) SIMPLE_CMD(cmd_clearerror, mpd_run_clearerror, 1) -SIMPLE_ONEARG_CMD(cmd_save, mpd_run_save, 0) SIMPLE_ONEARG_CMD(cmd_rm, mpd_run_rm, 0) /** @@ -1376,3 +1375,16 @@ cmd_partitiondelete(int argc, char **argv, struct mpd_connection *conn) { } return 0; } + +int +cmd_save(gcc_unused int argc, char **argv, struct mpd_connection *conn) +{ + if (options.force) { + if (!mpd_send_save_queue(conn, charset_to_utf8(argv[0]), MPD_QUEUE_SAVE_MODE_REPLACE)) + printErrorAndExit(conn); + } else { + if (!mpd_run_save(conn, charset_to_utf8(argv[0]))) + printErrorAndExit(conn); + } + return 0; +} diff --git a/src/options.c b/src/options.c index 807efed..beeedb8 100644 --- a/src/options.c +++ b/src/options.c @@ -48,6 +48,7 @@ static const struct OptionDef option_table[] = { { 'w', "wait", NULL, "Wait for operation to finish (e.g. database update)" }, { 'r', "range", "[]:[]", "Operate on a range (e.g. when loading a playlist)" }, { 'a', "partition", "", "Operate on partition instead" }, + { 'F', "force", NULL, "Force some operations (like saving playlist)" }, { OPTION_WITH_PRIO, "with-prio", NULL, "Show only songs that have a non-zero priority" }, }; @@ -164,6 +165,10 @@ handle_option(int c, const char *arg) options.wait = true; break; + case 'F': + options.force = true; + break; + case 'r': ParseRange(&options.range, arg); break; diff --git a/src/options.h b/src/options.h index 95e9392..e3bde11 100644 --- a/src/options.h +++ b/src/options.h @@ -28,6 +28,7 @@ struct Options { int verbosity; // 0 for quiet, 1 for default, 2 for verbose bool wait; + bool force; bool custom_format;