CLI: Implemented delete command for bookmarks and playlists.
This commit is contained in:
		@@ -50,11 +50,14 @@ remove <selection-criteria> from playlist <id | name>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
clear playlist <id | name>
 | 
					clear playlist <id | name>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					delete playlist <id | name>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Bookmarking
 | 
					# Bookmarking
 | 
				
			||||||
 | 
					
 | 
				
			||||||
create bookmark named <name>
 | 
					create bookmark named <name>
 | 
				
			||||||
create bookmark named <name> on <playlist id | name> at <media file id | name>
 | 
					create bookmark named <name> on <playlist id | name> at <media file id | name>
 | 
				
			||||||
rename bookmark <old name> to <new name>
 | 
					rename bookmark <old name> to <new name>
 | 
				
			||||||
 | 
					delete bookmark <name | id>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Transport Functions
 | 
					# Transport Functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -77,7 +77,7 @@ Options:
 | 
				
			|||||||
Configuration:
 | 
					Configuration:
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static Logger logger =
 | 
					    p2rivate static Logger logger =
 | 
				
			||||||
        LoggerFactory.getLogger(CommandLineInterface)
 | 
					        LoggerFactory.getLogger(CommandLineInterface)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private Properties cliConfig
 | 
					    private Properties cliConfig
 | 
				
			||||||
@@ -404,6 +404,7 @@ Configuration:
 | 
				
			|||||||
            case 'list':        return processList(rest, currentSelection)
 | 
					            case 'list':        return processList(rest, currentSelection)
 | 
				
			||||||
            case 'select':      return processSelect(rest, currentSelection)
 | 
					            case 'select':      return processSelect(rest, currentSelection)
 | 
				
			||||||
            case 'create':      return processCreate(rest, currentSelection)
 | 
					            case 'create':      return processCreate(rest, currentSelection)
 | 
				
			||||||
 | 
					            case 'delete':      return processDelete(rest)
 | 
				
			||||||
            case 'play':        return processPlay(rest, currentSelection)
 | 
					            case 'play':        return processPlay(rest, currentSelection)
 | 
				
			||||||
            case 'enqueue':     return processEnqueue(rest, currentSelection)
 | 
					            case 'enqueue':     return processEnqueue(rest, currentSelection)
 | 
				
			||||||
            case 'add':         return processAdd(rest, currentSelection)
 | 
					            case 'add':         return processAdd(rest, currentSelection)
 | 
				
			||||||
@@ -610,6 +611,18 @@ Configuration:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            default: invalidOptionsErr('create') } }
 | 
					            default: invalidOptionsErr('create') } }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private def processDelete(String options) {
 | 
				
			||||||
 | 
					        switch (options) {
 | 
				
			||||||
 | 
					            case ~/playlist (.+)/:
 | 
				
			||||||
 | 
					                Playlist p = getExactlyOne(
 | 
				
			||||||
 | 
					                    Playlist, Matcher.lastMatcher[0][1].trim())
 | 
				
			||||||
 | 
					                return library.delete(p)
 | 
				
			||||||
 | 
					            case ~/bookmark (.+)/:
 | 
				
			||||||
 | 
					                Bookmark b = getExactlyOne(
 | 
				
			||||||
 | 
					                    Bookmark, Matcher.latMatcher[0][1].trim())
 | 
				
			||||||
 | 
					                return library.delete(b)
 | 
				
			||||||
 | 
					            default: invalidOptionsErr('delete') } }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private Playlist processPlay(String options, List<Model> selection) {
 | 
					    private Playlist processPlay(String options, List<Model> selection) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        switch (options) {
 | 
					        switch (options) {
 | 
				
			||||||
@@ -670,7 +683,7 @@ Configuration:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        Playlist p
 | 
					        Playlist p
 | 
				
			||||||
        def m = (options =~ /(.+) to playlist (.+)/)
 | 
					        def m = (options =~ /(.+) to playlist (.+)/)
 | 
				
			||||||
        p = getExactlyOne(m[0][2])
 | 
					        p = getExactlyOne(Playlist, m[0][2])
 | 
				
			||||||
        if (!p) err "No playlist for '${Matcher.lastMatcher[0][1]}'."
 | 
					        if (!p) err "No playlist for '${Matcher.lastMatcher[0][1]}'."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (m[0][1] != "selection") selection = select(options, selection)
 | 
					        if (m[0][1] != "selection") selection = select(options, selection)
 | 
				
			||||||
@@ -936,6 +949,7 @@ Available commands:
 | 
				
			|||||||
    select      Select things (into the select buffer, no the play queue).
 | 
					    select      Select things (into the select buffer, no the play queue).
 | 
				
			||||||
    play        Play requested media.
 | 
					    play        Play requested media.
 | 
				
			||||||
    enqueue     Enqueue requested media to the end of the play queue.
 | 
					    enqueue     Enqueue requested media to the end of the play queue.
 | 
				
			||||||
 | 
					    create      Create a playlist or bookmark.
 | 
				
			||||||
    add         Append requested media to the end of a playlist.
 | 
					    add         Append requested media to the end of a playlist.
 | 
				
			||||||
    remove      Remove requested from the play queue or playlist.
 | 
					    remove      Remove requested from the play queue or playlist.
 | 
				
			||||||
    randomize   Re-order the files in a play queue or a playlist randomly.
 | 
					    randomize   Re-order the files in a play queue or a playlist randomly.
 | 
				
			||||||
@@ -1074,6 +1088,15 @@ ${cmdStyle}create playlist named <name> from { queue | selection}${normalStyle}
 | 
				
			|||||||
    current play queue or the current selection.
 | 
					    current play queue or the current selection.
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // DELETE
 | 
				
			||||||
 | 
					            // --------------
 | 
				
			||||||
 | 
					            case 'delete': return """\
 | 
				
			||||||
 | 
					${cmdStyle}delete playlist <name | id>
 | 
				
			||||||
 | 
					delete bookmark <name | id>${normalStyle}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Delete a playlist or bookmark.
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // PLAY
 | 
					            // PLAY
 | 
				
			||||||
            // --------------
 | 
					            // --------------
 | 
				
			||||||
            case 'play': return """\
 | 
					            case 'play': return """\
 | 
				
			||||||
@@ -1336,10 +1359,14 @@ Playlist and Queue Management:
 | 
				
			|||||||
    create bookmark named <name> on playlist <playlist name | id> at <file name | id>
 | 
					    create bookmark named <name> on playlist <playlist name | id> at <file name | id>
 | 
				
			||||||
    create playlist named <name> from { selection | queue }
 | 
					    create playlist named <name> from { selection | queue }
 | 
				
			||||||
    create playlist named <name from <selection-criteria>
 | 
					    create playlist named <name from <selection-criteria>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    copy playlist <id | name> as <new name>
 | 
					    copy playlist <id | name> as <new name>
 | 
				
			||||||
    create bookmark <id | name>
 | 
					    create bookmark <id | name>
 | 
				
			||||||
    update bookmark <id | name>
 | 
					    update bookmark <id | name>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    delete playlist <id | name>
 | 
				
			||||||
 | 
					    delete bookmark <id | name>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    randomize queue
 | 
					    randomize queue
 | 
				
			||||||
    randomize playlist
 | 
					    randomize playlist
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -637,6 +637,11 @@ public class DbApi {
 | 
				
			|||||||
        return sql.rows(query, sqlParams)
 | 
					        return sql.rows(query, sqlParams)
 | 
				
			||||||
            .collect { recordToModel(Playlist, it) } }
 | 
					            .collect { recordToModel(Playlist, it) } }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int delete(Playlist p) {
 | 
				
			||||||
 | 
					        return withTransaction {
 | 
				
			||||||
 | 
					            removeAllFromPlaylist(p.id)
 | 
				
			||||||
 | 
					            delete((Model) p) } }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public int getNextPlaylistPosition(UUID playlistId) {
 | 
					    public int getNextPlaylistPosition(UUID playlistId) {
 | 
				
			||||||
        String query = """\
 | 
					        String query = """\
 | 
				
			||||||
            SELECT COALESCE(MAX(position), 0) + 1
 | 
					            SELECT COALESCE(MAX(position), 0) + 1
 | 
				
			||||||
@@ -740,7 +745,8 @@ public class DbApi {
 | 
				
			|||||||
            logger.debug(
 | 
					            logger.debug(
 | 
				
			||||||
                'Finding media file playlist position.\n\tSQL: {}\n\tPARAMS: {}',
 | 
					                'Finding media file playlist position.\n\tSQL: {}\n\tPARAMS: {}',
 | 
				
			||||||
                getPositionQuery, params)
 | 
					                getPositionQuery, params)
 | 
				
			||||||
            int position = sql.firstRow(getPositionQuery, params)[0]
 | 
					            def row = sql.firstRow(getPositionQuery, params)
 | 
				
			||||||
 | 
					            int position = row ? row[0] : 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            logger.debug(
 | 
					            logger.debug(
 | 
				
			||||||
                'Removing media file from playlist.\n\tSQL: {}\n\tPARAMS: {}',
 | 
					                'Removing media file from playlist.\n\tSQL: {}\n\tPARAMS: {}',
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user