Added and commands to CLI.

This commit is contained in:
Jonathan Bernard 2016-08-01 06:25:03 -05:00
parent ffcfc7bc77
commit 4507c6b664
2 changed files with 48 additions and 7 deletions

View File

@ -12,7 +12,7 @@ allprojects {
} }
group = 'com.jdbernard' group = 'com.jdbernard'
version = '0.1.0' version = '0.1.1'
repositories { repositories {
mavenLocal() mavenLocal()

View File

@ -28,7 +28,7 @@ import static com.jdbernard.wdiwtlt.cli.CliErr.*
public class CommandLineInterface { public class CommandLineInterface {
public static final VERSION = "ALPHA" public static final VERSION = "0.1.1"
public static final def DOC = """\ public static final def DOC = """\
wdiwtlt v$VERSION wdiwtlt v$VERSION
@ -125,6 +125,7 @@ Configuration:
private ScrollText status = new ScrollText(maxWidth: displayWidth) private ScrollText status = new ScrollText(maxWidth: displayWidth)
private Date dismissMsgDate = new Date() private Date dismissMsgDate = new Date()
private SimpleDateFormat sdf = new SimpleDateFormat('EEE-HH-SSS') private SimpleDateFormat sdf = new SimpleDateFormat('EEE-HH-SSS')
private Random rand = new Random()
/// Current play queue and selection data /// Current play queue and selection data
List<Model> currentSelection = [] List<Model> currentSelection = []
@ -503,6 +504,7 @@ Configuration:
Class modelClass Class modelClass
switch (options) { switch (options) {
case ~/selection/: return selection;
case ~/playing ($selectableModels)s?/: case ~/playing ($selectableModels)s?/:
if (!curMediaFile) err "No media is currently playing." if (!curMediaFile) err "No media is currently playing."
@ -513,10 +515,29 @@ Configuration:
else return library.getWhere(modelClass, else return library.getWhere(modelClass,
[mediaFileId: curMediaFile.id]) [mediaFileId: curMediaFile.id])
/* TODO case ~/(\d+ )?random ($selectableModels)s?( from (.+$))?/:
case ~/files tagged as((\s\w+)+?) and not as((\s\w+)+)/: modelClass = modelClasses[Matcher.lastMatcher[0][2]]
excludedTags = lastMatcher[0][3].split(/\s/) def sourceCriteria = Matcher.lastMatcher[0][4]?.trim()
*/ int count = (Matcher.lastMatcher[0][1] ?: 1) as int
def source
if (sourceCriteria) {
source = select(sourceCriteria, selection)
if (modelClass != source[0].class) {
source = source.collectMany { library.getWhere(modelClass,
[(idKeyFor(source[0].class)): it.id]) }
.findAll().unique() } }
else source = library.getAll(modelClass);
if (source.size() < count)
err "There are not ${count} ${toEnglish(modelClass)}s to select."
def selected = []
(0..<count).each {
selected << source.remove(rand.nextInt(source.size())) }
return selected
case ~/selected ($selectableModels)s?/: case ~/selected ($selectableModels)s?/:
@ -543,6 +564,18 @@ Configuration:
// TODO // TODO
err "select <thing> where ... is not yet implemented." err "select <thing> where ... is not yet implemented."
case ~/($selectableModels)s? from (.+)/:
modelClass = modelClasses[Matcher.lastMatcher[0][1]]
def sourceCriteria = Matcher.lastMatcher[0][2].trim()
def models = select(sourceCriteria, selection)
if (modelClass != models[0].class) {
models = models.collectMany { library.getWhere(modelClass,
[(idKeyFor(models[0].class)): it.id]) }
.findAll().unique() }
return models;
case ~/($selectableModels)s((\s\d+)+)/: case ~/($selectableModels)s((\s\d+)+)/:
modelClass = modelClasses[Matcher.lastMatcher[0][1]] modelClass = modelClasses[Matcher.lastMatcher[0][1]]
return Matcher.lastMatcher[0][2].split(/\s/) return Matcher.lastMatcher[0][2].split(/\s/)
@ -1038,10 +1071,18 @@ ${cmdStyle}select playing { album | artist | file | playlist | tag }${normalStyl
this selects items that are associated with the currently playing media this selects items that are associated with the currently playing media
file. file.
${cmdStyle}queued { albums | artists | files | playlists | tags }${normalStyle} ${cmdStyle}select queued { albums | artists | files | playlists | tags }${normalStyle}
Select the items currently in the queue. Select the items currently in the queue.
${cmdStyle}select <count> random {albums | artists | files | playlists | tags }${normalStyle}
Select one or more items randomly.
${cmdStyle}select <count> random {albums | artists | files | playlists | tags } from <select-criteria>${normalStyle}
Make a selection, then select one or more items randomly from it.
${cmdStyle}select selected { album | artist | file | playlist | tag }${normalStyle} ${cmdStyle}select selected { album | artist | file | playlist | tag }${normalStyle}
Select the items associated with the current selection buffer into the Select the items associated with the current selection buffer into the