From e6228ab6141445b1f9dc2b3a0256522a9a47bfb6 Mon Sep 17 00:00:00 2001 From: Osman Altun Date: Thu, 15 Jul 2021 00:38:52 +0200 Subject: [PATCH] feat: allow script arguments (#176) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: playerArgs.smplayer typo * fix: chromecast logic * feat: allow script arguments Co-authored-by: Diego Rodríguez Baquero --- bin/cmd.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/bin/cmd.js b/bin/cmd.js index 324fa796..9649e028 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -199,13 +199,11 @@ function init (_argv) { } if (argv.onDone) { - checkPermission(argv.onDone) - argv.onDone = argv['on-done'] = fs.realpathSync(argv.onDone) + argv.onDone = argv['on-done'] = argv.onDone.split(' ') } if (argv.onExit) { - checkPermission(argv.onExit) - argv.onExit = argv['on-exit'] = fs.realpathSync(argv.onExit) + argv.onExit = argv['on-exit'] = argv.onExit.split(' ') } if (playerName && argv.playerArgs) { @@ -319,8 +317,11 @@ function runDownload (torrentId) { console.log(chalk`\ntorrent downloaded {green successfully} from {bold ${numActiveWires}/${torrent.numPeers}} {green peers} in {bold ${getRuntime()}s}!`) } - if (argv['on-done']) { - cp.exec(argv['on-done']).unref() + if (argv.onDone) { + cp.spawn(argv.onDone[0], argv.onDone.slice(1), { shell: true } ) + .on('error', (err) => fatalError(err)) + .stderr.on('data', (err) => fatalError(err)) + .unref() } if (!playerName && !serving && argv.out && !argv['keep-seeding']) { torrent.destroy() @@ -763,8 +764,11 @@ function gracefulExit () { clearInterval(drawInterval) - if (argv['on-exit']) { - cp.exec(argv['on-exit']).unref() + if (argv.onExit) { + cp.spawn(argv.onExit[0], argv.onExit.slice(1), { shell: true } ) + .on('error', (err) => fatalError(err)) + .stderr.on('data', (err) => fatalError(err)) + .unref() } client.destroy(err => { @@ -779,16 +783,6 @@ function gracefulExit () { }) } -function checkPermission (filename) { - try { - if (!executable.sync(filename)) { - return errorAndExit(`Script "${filename}" is not executable`) - } - } catch (err) { - return errorAndExit(`Script "${filename}" does not exist`) - } -} - function enableQuiet () { argv.quiet = argv.q = true }