« get me outta code hell

Make -k and -x fail when the passed group path is not perfectly found - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2017-10-25 09:26:53 -0300
committerFlorrie <towerofnix@gmail.com>2017-10-25 09:26:53 -0300
commitaac119f2162dc981fa4b6fcba5e8301e7625a011 (patch)
tree4b22a887349b3cffdf4a6d40439996c37f8716fb
parente447c564e9823a32c25aa1c9309c9b13d5225933 (diff)
Make -k and -x fail when the passed group path is not perfectly found
-rwxr-xr-xsrc/play.js5
-rw-r--r--src/playlist-utils.js6
-rw-r--r--todo.txt1
3 files changed, 10 insertions, 2 deletions
diff --git a/src/play.js b/src/play.js
index 8f52e63..c754836 100755
--- a/src/play.js
+++ b/src/play.js
@@ -302,7 +302,10 @@ async function main(args) {
 
       const pathString = util.nextArg()
       const group = filterPlaylistByPathString(sourcePlaylist, pathString)
-      activePlaylist.items.push(group)
+
+      if (group) {
+        activePlaylist.items.push(group)
+      }
     },
 
     'k': util => util.alias('-keep'),
diff --git a/src/playlist-utils.js b/src/playlist-utils.js
index a75008a..d19c571 100644
--- a/src/playlist-utils.js
+++ b/src/playlist-utils.js
@@ -261,7 +261,7 @@ function filterGrouplikeByPath(grouplike, pathParts) {
     }
   } else {
     console.warn(`Not found: "${pathParts[0]}"`)
-    return grouplike
+    return null
   }
 }
 
@@ -276,6 +276,10 @@ function removeGroupByPath(playlist, pathParts) {
 
   const groupToRemove = filterGrouplikeByPath(playlist, pathParts)
 
+  if (groupToRemove === null) {
+    return
+  }
+
   if (playlist === groupToRemove) {
     console.error(
       'You can\'t remove the playlist from itself! Instead, try --clear' +
diff --git a/todo.txt b/todo.txt
index 4250825..48f06b2 100644
--- a/todo.txt
+++ b/todo.txt
@@ -233,6 +233,7 @@ TODO: Make a YouTube playlist crawler.
 
 TODO: The filter utility function shouldn't work at all if it fails to find
       what it's looking for.
+      (Done!)
 
 TODO: Make the filter/remove/keep options do a search of some sort.