« get me outta code hell

http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/command-exists.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/command-exists.js')
-rwxr-xr-xsrc/command-exists.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/command-exists.js b/src/command-exists.js
new file mode 100755
index 0000000..9921364
--- /dev/null
+++ b/src/command-exists.js
@@ -0,0 +1,12 @@
+const npmCommandExists = require('command-exists')
+
+module.exports = 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
+  }
+}