« get me outta code hell

Make commandExists actually work when a command doesn't exist - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorliam4 <towerofnix@gmail.com>2017-07-24 20:39:31 -0300
committerliam4 <towerofnix@gmail.com>2017-07-24 20:39:31 -0300
commitbb1a0d08e408f949d3b94206f8b5883a659f4d0d (patch)
tree9e9112f72e65246daacbf605d2d7219abed3e95c /src
parent39e0b6051e49165d56ba0e88484cb18f9f20de66 (diff)
Make commandExists actually work when a command doesn't exist
Diffstat (limited to 'src')
-rwxr-xr-xsrc/play.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/play.js b/src/play.js
index a94e2aa..35001be 100755
--- a/src/play.js
+++ b/src/play.js
@@ -6,7 +6,7 @@ const { promisify } = require('util')
 const clone = require('clone')
 const fs = require('fs')
 const fetch = require('node-fetch')
-const commandExists = require('command-exists')
+const npmCommandExists = require('command-exists')
 const pickers = require('./pickers')
 const loopPlay = require('./loop-play')
 const processArgv = require('./process-argv')
@@ -40,6 +40,17 @@ function clearConsoleLine() {
   process.stdout.write('\x1b[1K\r')
 }
 
+async function commandExists(command) {
+  // When the command-exists module sees that a given command doesn't exist, it
+  // throws an error instead of returning false, which is not what we want.
+
+  try {
+    return await npmCommandExists(command)
+  } catch(err) {
+    return false
+  }
+}
+
 async function determineDefaultPlayer() {
   if (await commandExists('mpv')) {
     return 'mpv'