Skip to content

Commit e6228ab

Browse files
feat: allow script arguments (#176)
* fix: playerArgs.smplayer typo * fix: chromecast logic * feat: allow script arguments Co-authored-by: Diego Rodríguez Baquero <github@diegorbaquero.com>
1 parent 310f04f commit e6228ab

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

bin/cmd.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,11 @@ function init (_argv) {
199199
}
200200

201201
if (argv.onDone) {
202-
checkPermission(argv.onDone)
203-
argv.onDone = argv['on-done'] = fs.realpathSync(argv.onDone)
202+
argv.onDone = argv['on-done'] = argv.onDone.split(' ')
204203
}
205204

206205
if (argv.onExit) {
207-
checkPermission(argv.onExit)
208-
argv.onExit = argv['on-exit'] = fs.realpathSync(argv.onExit)
206+
argv.onExit = argv['on-exit'] = argv.onExit.split(' ')
209207
}
210208

211209
if (playerName && argv.playerArgs) {
@@ -319,8 +317,11 @@ function runDownload (torrentId) {
319317

320318
console.log(chalk`\ntorrent downloaded {green successfully} from {bold ${numActiveWires}/${torrent.numPeers}} {green peers} in {bold ${getRuntime()}s}!`)
321319
}
322-
if (argv['on-done']) {
323-
cp.exec(argv['on-done']).unref()
320+
if (argv.onDone) {
321+
cp.spawn(argv.onDone[0], argv.onDone.slice(1), { shell: true } )
322+
.on('error', (err) => fatalError(err))
323+
.stderr.on('data', (err) => fatalError(err))
324+
.unref()
324325
}
325326
if (!playerName && !serving && argv.out && !argv['keep-seeding']) {
326327
torrent.destroy()
@@ -763,8 +764,11 @@ function gracefulExit () {
763764

764765
clearInterval(drawInterval)
765766

766-
if (argv['on-exit']) {
767-
cp.exec(argv['on-exit']).unref()
767+
if (argv.onExit) {
768+
cp.spawn(argv.onExit[0], argv.onExit.slice(1), { shell: true } )
769+
.on('error', (err) => fatalError(err))
770+
.stderr.on('data', (err) => fatalError(err))
771+
.unref()
768772
}
769773

770774
client.destroy(err => {
@@ -779,16 +783,6 @@ function gracefulExit () {
779783
})
780784
}
781785

782-
function checkPermission (filename) {
783-
try {
784-
if (!executable.sync(filename)) {
785-
return errorAndExit(`Script "${filename}" is not executable`)
786-
}
787-
} catch (err) {
788-
return errorAndExit(`Script "${filename}" does not exist`)
789-
}
790-
}
791-
792786
function enableQuiet () {
793787
argv.quiet = argv.q = true
794788
}

0 commit comments

Comments
 (0)