From 4507c6b66411c470a323e0c3e3259d063ed52866 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Mon, 1 Aug 2016 06:25:03 -0500 Subject: [PATCH] Added and commands to CLI. --- build.gradle | 2 +- .../wdiwtlt/cli/CommandLineInterface.groovy | 53 ++++++++++++++++--- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index cd76976..b436a95 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ allprojects { } group = 'com.jdbernard' - version = '0.1.0' + version = '0.1.1' repositories { mavenLocal() diff --git a/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy b/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy index fa3bb1d..a1aeb13 100644 --- a/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy +++ b/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy @@ -28,7 +28,7 @@ import static com.jdbernard.wdiwtlt.cli.CliErr.* public class CommandLineInterface { - public static final VERSION = "ALPHA" + public static final VERSION = "0.1.1" public static final def DOC = """\ wdiwtlt v$VERSION @@ -125,6 +125,7 @@ Configuration: private ScrollText status = new ScrollText(maxWidth: displayWidth) private Date dismissMsgDate = new Date() private SimpleDateFormat sdf = new SimpleDateFormat('EEE-HH-SSS') + private Random rand = new Random() /// Current play queue and selection data List currentSelection = [] @@ -503,6 +504,7 @@ Configuration: Class modelClass switch (options) { + case ~/selection/: return selection; case ~/playing ($selectableModels)s?/: if (!curMediaFile) err "No media is currently playing." @@ -513,10 +515,29 @@ Configuration: else return library.getWhere(modelClass, [mediaFileId: curMediaFile.id]) - /* TODO - case ~/files tagged as((\s\w+)+?) and not as((\s\w+)+)/: - excludedTags = lastMatcher[0][3].split(/\s/) - */ + case ~/(\d+ )?random ($selectableModels)s?( from (.+$))?/: + modelClass = modelClasses[Matcher.lastMatcher[0][2]] + 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.. 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+)+)/: modelClass = modelClasses[Matcher.lastMatcher[0][1]] 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 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. +${cmdStyle}select random {albums | artists | files | playlists | tags }${normalStyle} + + Select one or more items randomly. + +${cmdStyle}select random {albums | artists | files | playlists | tags } from ${normalStyle} + + Make a selection, then select one or more items randomly from it. + ${cmdStyle}select selected { album | artist | file | playlist | tag }${normalStyle} Select the items associated with the current selection buffer into the