Skip to content

Commit

Permalink
feat: allow script arguments (#176)
Browse files Browse the repository at this point in the history
* fix: playerArgs.smplayer typo

* fix: chromecast logic

* feat: allow script arguments

Co-authored-by: Diego Rodríguez Baquero <[email protected]>
  • Loading branch information
OsmanAltun and DiegoRBaquero authored Jul 14, 2021
1 parent 310f04f commit e6228ab
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 => {
Expand All @@ -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
}
Expand Down

0 comments on commit e6228ab

Please sign in to comment.