Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couple of changes to cmd.js #600

Closed
wants to merge 12 commits into from

Added --exit, -e argument to exit webtorrent on completion.

Signed-off-by: Vincent Frentzel <vincent@frentzel.eu>
  • Loading branch information
Vincent Frentzel
Vincent Frentzel committed Feb 7, 2016
commit 4ba81351772ea593543ab2cb4e8bf7f3d382fa99
@@ -48,7 +48,8 @@ var argv = minimist(process.argv.slice(2), {
a: 'announce',
q: 'quiet',
h: 'help',
v: 'version'
v: 'version',
e: 'exit'
},
boolean: [ // options that are always boolean
'airplay',
@@ -62,7 +63,8 @@ var argv = minimist(process.argv.slice(2), {
'quiet',
'help',
'version',
'verbose'
'verbose',
'exit'
],
string: [ // options that are always strings
'out',
@@ -211,6 +213,7 @@ Options (advanced):
-b, --blocklist [path] load blocklist file/http url
-a, --announce [url] tracker URL to announce to
-q, --quiet don't show UI on stdout
-e, --exit exit webtorrent on completion
--on-done [script] run script after torrent download is done
--on-exit [script] run script before program exit
--verbose show torrent protocol details
@@ -303,22 +306,7 @@ function runDownload (torrentId) {
)
})

torrent.on('done', function () {
if (!argv.quiet) {
var numActiveWires = torrent.swarm.wires.reduce(function (num, wire) {
return num + (wire.downloaded > 0)
}, 0)
clivas.line('')
clivas.line(
'torrent downloaded {green:successfully} from {bold:%s/%s} {green:peers} ' +
'in {bold:%ss}!',
numActiveWires,
torrent.numPeers,
getRuntime()
)
}
torrentDone()
})
torrent.on('done', torrentDone)

// Start http server
server = torrent.createServer()
@@ -604,6 +592,7 @@ function drawTorrent (torrent) {

function torrentDone () {
if (argv['on-done']) cp.exec(argv['on-done']).unref()
if (argv['exit']) gracefulExit()
}

function fatalError (err) {
@@ -100,7 +100,7 @@ test('Command line: webtorrent create /path/to/file', function (t) {
test('Command line: webtorrent download <torrent file> (with local content)', function (t) {
t.plan(2)

cp.exec(CMD + ' download ' + common.leaves.torrentPath + ' --out test/fixtures', function (err, data) {
cp.exec(CMD + ' download ' + common.leaves.torrentPath + ' --out test/fixtures' + ' --exit', function (err, data) {
t.error(err)
t.ok(data.indexOf('successfully') !== -1)
})
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.