diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2015-01-11 06:59:53 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2015-01-11 06:59:53 +0300 |
commit | ac3584b31b68a21b27a9ba40f96249debbf6fcad (patch) | |
tree | cbc492958e8b5518adb6d794143cc0cc5fe9469c /bin | |
parent | 198ac76f6c476cee4b5d1774f9b667777a7d9b54 (diff) |
command line: add `create` command
Fixes #232
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/cmd.js | 27 |
1 files changed, 24 insertions, 3 deletions
@@ -1,5 +1,6 @@ #!/usr/bin/env node +var createTorrent = require('create-torrent') var clivas = require('clivas') var cp = require('child_process') var fs = require('fs') @@ -66,6 +67,9 @@ if (command === 'help' || argv.help) { } else if (command === 'info') { torrentId = argv._[1] info(torrentId) +} else if (command === 'create') { + var input = argv._[1] + create(input) } else if (command === 'download') { torrentId = argv._[1] download(torrentId) @@ -102,8 +106,9 @@ function help () { webtorrent download "magnet:?xt=urn:btih:..." --vlc Available commands: - download download a torrent - info show info for a .torrent file or magnet uri + download Download a torrent + create Create a .torrent file + info Show info for a .torrent file or magnet uri Specify torrents as one of the following: * magnet uri @@ -151,7 +156,23 @@ function info (torrentId) { delete parsedTorrent.info delete parsedTorrent.infoBuffer - console.log(JSON.stringify(parsedTorrent, undefined, 2)) + var output = JSON.stringify(parsedTorrent, undefined, 2) + if (argv.out) { + fs.writeFileSync(argv.out, output) + } else { + process.stdout.write(output) + } +} + +function create (input) { + createTorrent(input, function (err, torrent) { + if (err) return errorAndExit(err) + if (argv.out) { + fs.writeFileSync(argv.out, torrent) + } else { + process.stdout.write(torrent) + } + }) } function download (torrentId) { |