WIP continuing implementation of CLI.
This commit is contained in:
parent
a1230dddfd
commit
f80ff182ad
@ -11,6 +11,7 @@ import com.zaxxer.hikari.HikariDataSource
|
||||
import org.docopt.Docopt
|
||||
import jline.console.ConsoleReader
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.regex.Pattern
|
||||
import java.util.regex.Matcher
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
@ -94,7 +95,7 @@ Configuration:
|
||||
/// Current play queue and selection data
|
||||
def selection = [:]
|
||||
Playlist playQueue = library.save(new Playlist(
|
||||
"CLI Queue ${sdf.format(new Date())}"))
|
||||
name: "CLI Queue ${sdf.format(new Date())}"))
|
||||
Bookmark playBookmark
|
||||
MediaFile curMediaFile
|
||||
|
||||
@ -306,35 +307,44 @@ Configuration:
|
||||
option = line.poll()
|
||||
switch (option) {
|
||||
case 'album':
|
||||
return select(Album, library.getAlbumsWhere({
|
||||
return selectMatches(Album, library.getAlbumsWhere({
|
||||
mediaFileId: curMediaFile.id}))
|
||||
case 'artist':
|
||||
return select(Artist, library.getArtistsWhere({
|
||||
return selectMatches(Artist, library.getArtistsWhere({
|
||||
mediaFileId: curMediaFile.id}))
|
||||
case 'playlist':
|
||||
return select(Playlist, playQueue)
|
||||
return selectMatches(Playlist, playQueue)
|
||||
case 'file':
|
||||
return select(MediaFile, curMediaFile)
|
||||
return selectMatches(MediaFile, curMediaFile)
|
||||
case 'tags':
|
||||
return select(Tag, library.getTagsWhere({
|
||||
mediaFileId: curMediaFile.id})
|
||||
default:
|
||||
return selectMatches(Tag, library.getTagsWhere({
|
||||
mediaFileId: curMediaFile.id}))
|
||||
default:
|
||||
setErr("Unrecognized option to ${promptStyle}select " +
|
||||
"current${errStyle}.")
|
||||
"current${errorStyle}.")
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
switch (option) {
|
||||
case 'album': return select(Album, library.getByIdOrName(line.join(' ')))
|
||||
case 'artist': return select(Artist, library.getByIdOrName(line.join(' ')))
|
||||
case 'playlist': return select(Playlist, library.getByIdOrName(line.join(' ')))
|
||||
case 'current': return select(Current, library.getByIdOrName(line.join(' ')))
|
||||
case 'file': return select(MediaFile, library.getByIdOrName(line.join(' ')))
|
||||
case 'tags': return select(Tag, library.getByIdOrName(line.join(' ')))
|
||||
case 'album':
|
||||
return selectMatches(Album,
|
||||
library.getByIdOrName(Album, line.join(' ')))
|
||||
case 'artist':
|
||||
return selectMatches(Artist,
|
||||
library.getByIdOrName(Artist, line.join(' ')))
|
||||
case 'playlist':
|
||||
return selectMatches(Playlist,
|
||||
library.getByIdOrName(Playlist, line.join(' ')))
|
||||
case 'file':
|
||||
return selectMatches(MediaFile,
|
||||
library.getByIdOrName(MediaFile, line.join(' ')))
|
||||
case 'tags':
|
||||
return selectMatches(Tag,
|
||||
library.getByIdOrName(Tag, line.join(' ')))
|
||||
|
||||
default:
|
||||
setErr("Unrecognized option to ${promptStyle}select${errStyle}")
|
||||
setErr("Unrecognized option to ${promptStyle}select${errorStyle}")
|
||||
return null
|
||||
}
|
||||
}
|
||||
@ -353,7 +363,6 @@ Configuration:
|
||||
}
|
||||
|
||||
private def processAdd(LinkedList line) {
|
||||
// Add takes the form of
|
||||
def options = line.poll()
|
||||
switch(option) {
|
||||
case 'playlist':
|
||||
@ -366,6 +375,26 @@ Configuration:
|
||||
}
|
||||
}
|
||||
|
||||
private def processEnqueue(LinkedList line) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
private def processTag(LinkedList line) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
private def processClear(LinkedList line) {
|
||||
def option = line.poll()
|
||||
switch(option) {
|
||||
case 'queue': library.removeAllFromPlaylist(playQueue.id)
|
||||
default:
|
||||
printLongMessage("Unrecognized option to the ${promptStyle}" +
|
||||
"add${normalStyle} command. Use ${promptStyle}help add" +
|
||||
"${normalStyle} to see a list of valid options.")
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
private def processList(LinkedList options) {
|
||||
logger.debug("Listing things. Options: $options")
|
||||
def option = options.poll()
|
||||
@ -469,18 +498,18 @@ Configuration:
|
||||
String key = uncapitalize(modelClass.simpleName)
|
||||
this.selection[key] = null }
|
||||
|
||||
public def select(Class modelClass, def matches) {
|
||||
String englishName = ${toEnglish(modelClass.simpleName}
|
||||
if (!matches) {
|
||||
public def selectMatches(Class modelClass, def matches) {
|
||||
String englishName = toEnglish(modelClass.simpleName)
|
||||
if (!matches) {
|
||||
setErr("No $englishName matches.");
|
||||
return null }
|
||||
else if (match.size() > 1) {
|
||||
else if (matches.size() > 1) {
|
||||
setErr("Multiple ${englishName}s match: " +
|
||||
matches.collect { "${it.id}: ${it.name}" }.join(', '))
|
||||
return null }
|
||||
|
||||
selection[uncapitalize(modelClass.simpleName)] = matches[0]
|
||||
resetStatus
|
||||
resetStatus()
|
||||
return matches[0] }
|
||||
|
||||
private void drawLeader(afterOutput = false) {
|
||||
@ -593,10 +622,10 @@ Configuration:
|
||||
|
||||
private static String uncapitalize(String s) {
|
||||
if (s == null) return null;
|
||||
if (s.lengh() < 2) return s.toLowerCase();
|
||||
if (s.length() < 2) return s.toLowerCase();
|
||||
return s[0].toLowerCase() + s[1..-1] }
|
||||
|
||||
private static String toEnglish(String modelName) {
|
||||
return UPPERCASE_PATTERN.matcher(name).
|
||||
return UPPERCASE_PATTERN.matcher(modelName).
|
||||
replaceAll(/$1 $2/).toLowerCase() }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user