diff options
Diffstat (limited to 'index.js')
-rwxr-xr-x[-rw-r--r--] | index.js | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/index.js b/index.js index 72c2383..e74f2eb 100644..100755 --- a/index.js +++ b/index.js @@ -1,7 +1,11 @@ +#!/usr/bin/env node + // omg I am tired of code const { AppElement } = require('./ui') const { updatePlaylistFormat } = require('./playlist-utils') +const fs = require('fs') +const util = require('util') const processSmartPlaylist = require('./smart-playlist') const ansi = require('./tui-lib/util/ansi') const CommandLineInterfacer = require('./tui-lib/util/CommandLineInterfacer') @@ -9,6 +13,8 @@ const EventEmitter = require('events') const Flushable = require('./tui-lib/util/Flushable') const Root = require('./tui-lib/ui/Root') +const readFile = util.promisify(fs.readFile) + // Hack to get around errors when piping many things to stdout/err // (from general-util promisifyProcess) process.stdout.setMaxListeners(Infinity) @@ -69,7 +75,23 @@ async function main() { flushable.write(ansi.moveCursor(0, 0)) flushable.write('Opening playlist...') flushable.flush() - grouplike = require(process.argv[2]) + + let grouplikeText + try { + grouplikeText = await readFile(process.argv[2]) + } catch (error) { + flushable.write('Error opening the passed file "' + process.argv[2] + '"!') + flushable.flush() + process.exit(1) + } + + try { + grouplike = JSON.parse(grouplikeText) + } catch (error) { + flushable.write('Error parsing the passed file as JSON!') + flushable.flush() + process.exit(1) + } } grouplike = await processSmartPlaylist(grouplike) |