diff --git a/src/cli/bin.js b/src/cli/bin.js index cd506046dc..0b02459ae1 100755 --- a/src/cli/bin.js +++ b/src/cli/bin.js @@ -39,33 +39,25 @@ const args = process.argv.slice(2) // Need to skip to avoid locking as these commands // don't require a daemon if (args[0] === 'daemon' || args[0] === 'init') { - return cli + cli .help() .strict(false) .completion() .parse(args) -} - -utils.getIPFS((err, ipfs, cleanup) => { - if (err) { - throw err - } - - // finalize cli setup - cli // eslint-disable-line - .help() - .strict(false) - .completion() - .parse(args, { - ipfs: ipfs - }, (err, argv, output) => { - if (output) { - console.log(output) - } - cleanup(() => { - if (err) { - throw err - } +} else { + utils.getIPFS((err, ipfs, cleanup) => { + if (err) { throw err } + + cli + .help() + .strict(false) + .completion() + .parse(args, { ipfs: ipfs }, (err, argv, output) => { + if (output) { console.log(output) } + + cleanup(() => { + if (err) { throw err } + }) }) - }) -}) + }) +} diff --git a/src/cli/commands/bitswap.js b/src/cli/commands/bitswap.js index 05284b9763..c262ffc77b 100644 --- a/src/cli/commands/bitswap.js +++ b/src/cli/commands/bitswap.js @@ -3,13 +3,13 @@ module.exports = { command: 'bitswap', - description: 'A set of commands to manipulate the bitswap agent.', + description: 'Interact with the bitswap agent.', builder (yargs) { - return yargs - .commandDir('bitswap') + return yargs.commandDir('bitswap') }, handler (argv) { + console.log('Type `jsipfs bitswap --help` for more information about this command') } } diff --git a/src/cli/commands/dns.js b/src/cli/commands/dns.js deleted file mode 100644 index fde8059af3..0000000000 --- a/src/cli/commands/dns.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -module.exports = { - command: 'dns', - - describe: '', - - handler (argv) { - } -} diff --git a/src/cli/commands/files.js b/src/cli/commands/files.js index ea8b41e2eb..b72d78534f 100644 --- a/src/cli/commands/files.js +++ b/src/cli/commands/files.js @@ -3,12 +3,14 @@ module.exports = { command: 'files', - description: 'Unixfs commands', + description: 'Operations over files (add, cat, get, ls, etc)', builder (yargs) { return yargs .commandDir('files') }, - handler (argv) {} + handler (argv) { + console.log('Type `jsipfs bitswap --help` for more instructions') + } } diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index 9d8b7beb7d..415dd431b9 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -36,6 +36,52 @@ function checkPath (inPath, recursive) { return inPath } +function addPipeline (index, addStream, list, wrapWithDirectory) { + pull( + zip( + pull.values(list), + pull( + pull.values(list), + paramap(fs.stat.bind(fs), 50) + ) + ), + pull.map((pair) => ({ + path: pair[0], + isDirectory: pair[1].isDirectory() + })), + pull.filter((file) => !file.isDirectory), + pull.map((file) => ({ + path: file.path.substring(index, file.path.length), + originalPath: file.path + })), + pull.map((file) => ({ + path: wrapWithDirectory ? path.join(WRAPPER, file.path) : file.path, + content: fs.createReadStream(file.originalPath) + })), + addStream, + pull.map((file) => ({ + hash: file.hash, + path: wrapWithDirectory ? file.path.substring(WRAPPER.length) : file.path + })), + pull.collect((err, added) => { + if (err) { + throw err + } + + sortBy(added, 'path') + .reverse() + .map((file) => { + const log = [ 'added', file.hash ] + + if (file.path.length > 0) log.push(file.path) + + return log.join(' ') + }) + .forEach((msg) => console.log(msg)) + }) + ) +} + module.exports = { command: 'add ', @@ -112,49 +158,3 @@ module.exports = { }) } } - -function addPipeline (index, addStream, list, wrapWithDirectory) { - pull( - zip( - pull.values(list), - pull( - pull.values(list), - paramap(fs.stat.bind(fs), 50) - ) - ), - pull.map((pair) => ({ - path: pair[0], - isDirectory: pair[1].isDirectory() - })), - pull.filter((file) => !file.isDirectory), - pull.map((file) => ({ - path: file.path.substring(index, file.path.length), - originalPath: file.path - })), - pull.map((file) => ({ - path: wrapWithDirectory ? path.join(WRAPPER, file.path) : file.path, - content: fs.createReadStream(file.originalPath) - })), - addStream, - pull.map((file) => ({ - hash: file.hash, - path: wrapWithDirectory ? file.path.substring(WRAPPER.length) : file.path - })), - pull.collect((err, added) => { - if (err) { - throw err - } - - sortBy(added, 'path') - .reverse() - .map((file) => { - const log = [ 'added', file.hash ] - - if (file.path.length > 0) log.push(file.path) - - return log.join(' ') - }) - .forEach((msg) => console.log(msg)) - }) - ) -} diff --git a/src/cli/commands/files/cat.js b/src/cli/commands/files/cat.js index 1294d79158..c64caad7a6 100644 --- a/src/cli/commands/files/cat.js +++ b/src/cli/commands/files/cat.js @@ -3,7 +3,7 @@ module.exports = { command: 'cat ', - describe: 'Download IPFS objects', + describe: 'Fetch and cat an IPFS path referencing a file', builder: {}, diff --git a/src/cli/commands/files/get.js b/src/cli/commands/files/get.js index ac19ca0aef..534a2d31f3 100644 --- a/src/cli/commands/files/get.js +++ b/src/cli/commands/files/get.js @@ -50,7 +50,7 @@ function fileHandler (dir) { module.exports = { command: 'get ', - describe: 'Download IPFS objects', + describe: 'Fetch a file or directory with files references from an IPFS Path', builder: { output: { diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js deleted file mode 100644 index d1210bdd28..0000000000 --- a/src/cli/commands/ls.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -module.exports = { - command: 'ls', - - describe: '', - - handler (argv) { - } -} diff --git a/src/cli/commands/mount.js b/src/cli/commands/mount.js deleted file mode 100644 index 7825753efb..0000000000 --- a/src/cli/commands/mount.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -module.exports = { - command: 'mount', - - describe: '', - - handler (argv) { - } -} diff --git a/src/cli/commands/ping.js b/src/cli/commands/ping.js deleted file mode 100644 index d6a040231c..0000000000 --- a/src/cli/commands/ping.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -module.exports = { - command: 'ping', - - describe: '', - - handler (argv) { - } -} diff --git a/src/cli/commands/refs.js b/src/cli/commands/refs.js deleted file mode 100644 index 3d4f4ef4ab..0000000000 --- a/src/cli/commands/refs.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -module.exports = { - command: 'refs', - - describe: '', - - handler (argv) { - } -} diff --git a/src/cli/commands/resolve.js b/src/cli/commands/resolve.js deleted file mode 100644 index d57a017114..0000000000 --- a/src/cli/commands/resolve.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -module.exports = { - command: 'resolve', - - describe: '', - - handler (argv) { - } -} diff --git a/src/cli/commands/update.js b/src/cli/commands/update.js deleted file mode 100644 index 56923c5699..0000000000 --- a/src/cli/commands/update.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -module.exports = { - command: 'update', - - describe: '', - - handler (argv) { - } -} diff --git a/test/cli/commands.js b/test/cli/commands.js index ed6b260e46..3305da9efe 100644 --- a/test/cli/commands.js +++ b/test/cli/commands.js @@ -4,7 +4,7 @@ const expect = require('chai').expect const runOnAndOff = require('../utils/on-and-off') -const commandCount = 63 +const commandCount = 56 describe('commands', () => runOnAndOff((thing) => { let ipfs