From bb1a0d08e408f949d3b94206f8b5883a659f4d0d Mon Sep 17 00:00:00 2001 From: liam4 Date: Mon, 24 Jul 2017 20:39:31 -0300 Subject: Make commandExists actually work when a command doesn't exist --- src/play.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/play.js') 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' -- cgit 1.3.0-6-gf8a5