diff --git a/src/cli/commands/bitswap/stat.js b/src/cli/commands/bitswap/stat.js index 081dceb595..6be9e4c9fa 100644 --- a/src/cli/commands/bitswap/stat.js +++ b/src/cli/commands/bitswap/stat.js @@ -1,8 +1,5 @@ 'use strict' -const CID = require('cids') -const print = require('../../utils').print - module.exports = { command: 'stat', @@ -11,6 +8,9 @@ module.exports = { builder: {}, handler (argv) { + const CID = require('cids') + const print = require('../../utils').print + argv.ipfs.bitswap.stat((err, stats) => { if (err) { throw err diff --git a/src/cli/commands/bitswap/wantlist.js b/src/cli/commands/bitswap/wantlist.js index 63692a993a..d59625d26a 100644 --- a/src/cli/commands/bitswap/wantlist.js +++ b/src/cli/commands/bitswap/wantlist.js @@ -1,7 +1,5 @@ 'use strict' -const print = require('../../utils').print - module.exports = { command: 'wantlist', @@ -16,6 +14,8 @@ module.exports = { }, handler (argv) { + const print = require('../../utils').print + // TODO: handle argv.peer argv.ipfs.bitswap.wantlist((err, res) => { if (err) { diff --git a/src/cli/commands/block/get.js b/src/cli/commands/block/get.js index ed753aeadb..83f328d0fc 100644 --- a/src/cli/commands/block/get.js +++ b/src/cli/commands/block/get.js @@ -1,7 +1,5 @@ 'use strict' -const CID = require('cids') - module.exports = { command: 'get ', @@ -10,6 +8,7 @@ module.exports = { builder: {}, handler (argv) { + const CID = require('cids') const cid = new CID(argv.key) argv.ipfs.block.get(cid, (err, block) => { diff --git a/src/cli/commands/block/put.js b/src/cli/commands/block/put.js index 9d75a9c72f..f938bad49b 100644 --- a/src/cli/commands/block/put.js +++ b/src/cli/commands/block/put.js @@ -1,36 +1,5 @@ 'use strict' -const CID = require('cids') -const multihashing = require('multihashing-async') -const bl = require('bl') -const fs = require('fs') -const Block = require('ipfs-block') -const waterfall = require('async/waterfall') -const print = require('../../utils').print - -function addBlock (data, opts) { - const ipfs = opts.ipfs - let cid - - waterfall([ - (cb) => multihashing(data, opts.mhtype || 'sha2-256', cb), - (multihash, cb) => { - if (opts.format !== 'dag-pb' || opts.version !== 0) { - cid = new CID(1, opts.format || 'dag-pb', multihash) - } else { - cid = new CID(0, 'dag-pb', multihash) - } - - ipfs.block.put(new Block(data, cid), cb) - } - ], (err) => { - if (err) { - throw err - } - print(cid.toBaseEncodedString()) - }) -} - module.exports = { command: 'put [block]', @@ -58,6 +27,37 @@ module.exports = { }, handler (argv) { + const CID = require('cids') + const multihashing = require('multihashing-async') + const bl = require('bl') + const fs = require('fs') + const Block = require('ipfs-block') + const waterfall = require('async/waterfall') + const print = require('../../utils').print + + function addBlock (data, opts) { + const ipfs = opts.ipfs + let cid + + waterfall([ + (cb) => multihashing(data, opts.mhtype || 'sha2-256', cb), + (multihash, cb) => { + if (opts.format !== 'dag-pb' || opts.version !== 0) { + cid = new CID(1, opts.format || 'dag-pb', multihash) + } else { + cid = new CID(0, 'dag-pb', multihash) + } + + ipfs.block.put(new Block(data, cid), cb) + } + ], (err) => { + if (err) { + throw err + } + print(cid.toBaseEncodedString()) + }) + } + if (argv.block) { const buf = fs.readFileSync(argv.block) return addBlock(buf, argv) diff --git a/src/cli/commands/block/rm.js b/src/cli/commands/block/rm.js index 71fc26726c..5e24a42ea8 100644 --- a/src/cli/commands/block/rm.js +++ b/src/cli/commands/block/rm.js @@ -1,9 +1,5 @@ 'use strict' -const utils = require('../../utils') -const mh = require('multihashes') -const print = utils.print - module.exports = { command: 'rm ', @@ -12,6 +8,9 @@ module.exports = { builder: {}, handler (argv) { + const utils = require('../../utils') + const print = utils.print + const mh = require('multihashes') if (utils.isDaemonOn()) { // TODO implement this once `js-ipfs-api` supports it throw new Error('rm block with daemon running is not yet implemented') diff --git a/src/cli/commands/block/stat.js b/src/cli/commands/block/stat.js index 07190fd225..0396faea69 100644 --- a/src/cli/commands/block/stat.js +++ b/src/cli/commands/block/stat.js @@ -1,8 +1,5 @@ 'use strict' -const CID = require('cids') -const print = require('../../utils').print - module.exports = { command: 'stat ', @@ -11,6 +8,8 @@ module.exports = { builder: {}, handler (argv) { + const CID = require('cids') + const print = require('../../utils').print argv.ipfs.block.stat(new CID(argv.key), (err, stats) => { if (err) { throw err diff --git a/src/cli/commands/bootstrap/add.js b/src/cli/commands/bootstrap/add.js index ebab4736c9..3d204d8550 100644 --- a/src/cli/commands/bootstrap/add.js +++ b/src/cli/commands/bootstrap/add.js @@ -1,7 +1,5 @@ 'use strict' -const print = require('../../utils').print - module.exports = { command: 'add []', @@ -16,6 +14,8 @@ module.exports = { }, handler (argv) { + const print = require('../../utils').print + argv.ipfs.bootstrap.add(argv.peer, { default: argv.default }, (err, list) => { diff --git a/src/cli/commands/bootstrap/list.js b/src/cli/commands/bootstrap/list.js index 4a9a76baee..0ef76fa358 100644 --- a/src/cli/commands/bootstrap/list.js +++ b/src/cli/commands/bootstrap/list.js @@ -1,7 +1,5 @@ 'use strict' -const print = require('../../utils').print - module.exports = { command: 'list', @@ -10,6 +8,8 @@ module.exports = { builder: {}, handler (argv) { + const print = require('../../utils').print + argv.ipfs.bootstrap.list((err, list) => { if (err) { throw err diff --git a/src/cli/commands/bootstrap/rm.js b/src/cli/commands/bootstrap/rm.js index cb8e398cc3..78908c31ec 100644 --- a/src/cli/commands/bootstrap/rm.js +++ b/src/cli/commands/bootstrap/rm.js @@ -1,10 +1,5 @@ 'use strict' -const debug = require('debug') -const log = debug('cli:bootstrap') -log.error = debug('cli:bootstrap:error') -const print = require('../../utils').print - module.exports = { command: 'rm []', @@ -19,6 +14,11 @@ module.exports = { }, handler (argv) { + const debug = require('debug') + const log = debug('cli:bootstrap') + log.error = debug('cli:bootstrap:error') + const print = require('../../utils').print + argv.ipfs.bootstrap.rm(argv.peer, { all: argv.all }, (err, list) => { diff --git a/src/cli/commands/commands.js b/src/cli/commands/commands.js index 176706ab3a..67d44ec431 100644 --- a/src/cli/commands/commands.js +++ b/src/cli/commands/commands.js @@ -1,7 +1,4 @@ 'use strict' -const print = require('../utils').print -const path = require('path') -const glob = require('glob').sync module.exports = { command: 'commands', @@ -9,6 +6,9 @@ module.exports = { describe: 'List all available commands', handler () { + const print = require('../utils').print + const path = require('path') + const glob = require('glob').sync const basePath = path.resolve(__dirname, '..') // modeled after https://github.com/vdemedes/ronin/blob/master/lib/program.js#L78 diff --git a/src/cli/commands/config.js b/src/cli/commands/config.js index a8741633c6..8d959bc380 100644 --- a/src/cli/commands/config.js +++ b/src/cli/commands/config.js @@ -1,6 +1,4 @@ 'use strict' -const print = require('../utils').print - module.exports = { command: 'config [value]', @@ -24,6 +22,8 @@ module.exports = { }, handler (argv) { + const print = require('../utils').print + if (argv._handled) { return } diff --git a/src/cli/commands/config/edit.js b/src/cli/commands/config/edit.js index 1238e4b4ad..0f76ad6ff5 100644 --- a/src/cli/commands/config/edit.js +++ b/src/cli/commands/config/edit.js @@ -1,12 +1,5 @@ 'use strict' -const spawn = require('child_process').spawn -const fs = require('fs') -const temp = require('temp') -const waterfall = require('async/waterfall') - -const utils = require('../../utils') - module.exports = { command: 'edit', @@ -15,6 +8,12 @@ module.exports = { builder: {}, handler (argv) { + const spawn = require('child_process').spawn + const fs = require('fs') + const temp = require('temp') + const waterfall = require('async/waterfall') + + const utils = require('../../utils') if (argv._handled) return argv._handled = true diff --git a/src/cli/commands/config/replace.js b/src/cli/commands/config/replace.js index eef322aaf3..06595d2033 100644 --- a/src/cli/commands/config/replace.js +++ b/src/cli/commands/config/replace.js @@ -1,9 +1,5 @@ 'use strict' -const path = require('path') -const fs = require('fs') -const utils = require('../../utils') - module.exports = { command: 'replace ', @@ -12,6 +8,10 @@ module.exports = { builder: {}, handler (argv) { + const path = require('path') + const fs = require('fs') + const utils = require('../../utils') + if (argv._handled) return argv._handled = true diff --git a/src/cli/commands/config/show.js b/src/cli/commands/config/show.js index be3730602b..646b2c86a2 100644 --- a/src/cli/commands/config/show.js +++ b/src/cli/commands/config/show.js @@ -1,10 +1,5 @@ 'use strict' -const debug = require('debug') -const log = debug('cli:config') -log.error = debug('cli:config:error') -const print = require('../../utils').print - module.exports = { command: 'show', @@ -13,6 +8,11 @@ module.exports = { builder: {}, handler (argv) { + const debug = require('debug') + const log = debug('cli:config') + log.error = debug('cli:config:error') + const print = require('../../utils').print + if (argv._handled) return argv._handled = true diff --git a/src/cli/commands/daemon.js b/src/cli/commands/daemon.js index 6c6e4d9d30..7291e09be1 100644 --- a/src/cli/commands/daemon.js +++ b/src/cli/commands/daemon.js @@ -1,11 +1,8 @@ 'use strict' -const HttpAPI = require('../../http') const utils = require('../utils') const print = utils.print -let httpAPI - module.exports = { command: 'daemon', @@ -29,10 +26,11 @@ module.exports = { }, handler (argv) { + const HttpAPI = require('../../http') print('Initializing daemon...') const repoPath = utils.getRepoPath() - httpAPI = new HttpAPI(process.env.IPFS_PATH, null, argv) + const httpAPI = new HttpAPI(process.env.IPFS_PATH, null, argv) httpAPI.start((err) => { if (err && err.code === 'ENOENT' && err.message.match(/Uninitalized repo/i)) { diff --git a/src/cli/commands/dag/get.js b/src/cli/commands/dag/get.js index 6088d2eb34..6c06eb3b53 100644 --- a/src/cli/commands/dag/get.js +++ b/src/cli/commands/dag/get.js @@ -1,8 +1,5 @@ 'use strict' -const CID = require('cids') -const print = require('../../utils').print - module.exports = { command: 'get ', @@ -16,6 +13,9 @@ module.exports = { }, handler (argv) { + const CID = require('cids') + const print = require('../../utils').print + const refParts = argv.cidpath.split('/') const cidString = refParts[0] const path = refParts.slice(1).join('/') diff --git a/src/cli/commands/dns.js b/src/cli/commands/dns.js index 5be09d12e1..721ad339c2 100644 --- a/src/cli/commands/dns.js +++ b/src/cli/commands/dns.js @@ -1,6 +1,4 @@ 'use strict' -const print = require('../utils').print - module.exports = { command: 'dns ', @@ -13,6 +11,8 @@ module.exports = { }, handler (argv) { + const print = require('../utils').print + argv.ipfs.dns(argv['domain'], (err, path) => { if (err) { throw err diff --git a/src/cli/commands/file/ls.js b/src/cli/commands/file/ls.js index 31abd73e60..1708326166 100644 --- a/src/cli/commands/file/ls.js +++ b/src/cli/commands/file/ls.js @@ -1,7 +1,5 @@ 'use strict' -const print = require('../../utils').print - module.exports = { command: 'ls ', @@ -10,6 +8,8 @@ module.exports = { builder: {}, handler (argv) { + const print = require('../../utils').print + let path = argv.key // `ipfs file ls` is deprecated. See https://ipfs.io/docs/commands/#ipfs-file-ls print(`This functionality is deprecated, and will be removed in future versions. If possible, please use 'ipfs ls' instead.`) diff --git a/src/cli/commands/files.js b/src/cli/commands/files.js index 1e24b3c226..47a14623d8 100644 --- a/src/cli/commands/files.js +++ b/src/cli/commands/files.js @@ -1,20 +1,20 @@ 'use strict' -const print = require('../utils').print -const lsCmd = require('./ls') - module.exports = { command: 'files ', description: 'Operations over files (add, cat, get, ls, etc)', builder (yargs) { + const lsCmd = require('./ls') return yargs .commandDir('files') .command(lsCmd) }, handler (argv) { + const print = require('../utils').print + print('Type `jsipfs files --help` for more instructions') } } diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index 1abedb5122..41ee62fa8b 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -1,105 +1,6 @@ 'use strict' -const fs = require('fs') -const path = require('path') -const glob = require('glob') -const sortBy = require('lodash.sortby') -const pull = require('pull-stream') -const paramap = require('pull-paramap') -const zip = require('pull-zip') -const getFolderSize = require('get-folder-size') -const byteman = require('byteman') -const waterfall = require('async/waterfall') const mh = require('multihashes') -const utils = require('../../utils') -const print = require('../../utils').print -const createProgressBar = require('../../utils').createProgressBar - -function checkPath (inPath, recursive) { - // This function is to check for the following possible inputs - // 1) "." add the cwd but throw error for no recursion flag - // 2) "." -r return the cwd - // 3) "/some/path" but throw error for no recursion - // 4) "/some/path" -r - // 5) No path, throw err - // 6) filename.type return the cwd + filename - - if (!inPath) { - throw new Error('Error: Argument \'path\' is required') - } - - if (inPath === '.') { - inPath = process.cwd() - } - - // Convert to POSIX format - inPath = inPath - .split(path.sep) - .join('/') - - // Strips trailing slash from path. - inPath = inPath.replace(/\/$/, '') - - if (fs.statSync(inPath).isDirectory() && recursive === false) { - throw new Error(`Error: ${inPath} is a directory, use the '-r' flag to specify directories`) - } - - return inPath -} - -function getTotalBytes (path, recursive, cb) { - if (recursive) { - getFolderSize(path, cb) - } else { - fs.stat(path, (err, stat) => cb(err, stat.size)) - } -} - -function addPipeline (index, addStream, list, argv) { - const { - quiet, - quieter, - silent - } = argv - 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), - content: fs.createReadStream(file.path) - })), - addStream, - pull.collect((err, added) => { - if (err) { - throw err - } - - if (silent) return - if (quieter) return print(added.pop().hash) - - sortBy(added, 'path') - .reverse() - .map((file) => { - const log = [ 'added', file.hash ] - - if (!quiet && file.path.length > 0) log.push(file.path) - - return log.join(' ') - }) - .forEach((msg) => print(msg)) - }) - ) -} module.exports = { command: 'add ', @@ -177,6 +78,106 @@ module.exports = { }, handler (argv) { + const fs = require('fs') + const path = require('path') + const glob = require('glob') + const sortBy = require('lodash.sortby') + const pull = require('pull-stream') + const paramap = require('pull-paramap') + const zip = require('pull-zip') + const getFolderSize = require('get-folder-size') + const byteman = require('byteman') + const waterfall = require('async/waterfall') + const utils = require('../../utils') + const print = require('../../utils').print + const createProgressBar = require('../../utils').createProgressBar + + function checkPath (inPath, recursive) { + // This function is to check for the following possible inputs + // 1) "." add the cwd but throw error for no recursion flag + // 2) "." -r return the cwd + // 3) "/some/path" but throw error for no recursion + // 4) "/some/path" -r + // 5) No path, throw err + // 6) filename.type return the cwd + filename + + if (!inPath) { + throw new Error('Error: Argument \'path\' is required') + } + + if (inPath === '.') { + inPath = process.cwd() + } + + // Convert to POSIX format + inPath = inPath + .split(path.sep) + .join('/') + + // Strips trailing slash from path. + inPath = inPath.replace(/\/$/, '') + + if (fs.statSync(inPath).isDirectory() && recursive === false) { + throw new Error(`Error: ${inPath} is a directory, use the '-r' flag to specify directories`) + } + + return inPath + } + + function getTotalBytes (path, recursive, cb) { + if (recursive) { + getFolderSize(path, cb) + } else { + fs.stat(path, (err, stat) => cb(err, stat.size)) + } + } + + function addPipeline (index, addStream, list, argv) { + const { + quiet, + quieter, + silent + } = argv + 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), + content: fs.createReadStream(file.path) + })), + addStream, + pull.collect((err, added) => { + if (err) { + throw err + } + + if (silent) return + if (quieter) return print(added.pop().hash) + + sortBy(added, 'path') + .reverse() + .map((file) => { + const log = [ 'added', file.hash ] + + if (!quiet && file.path.length > 0) log.push(file.path) + + return log.join(' ') + }) + .forEach((msg) => print(msg)) + }) + ) + } + const inPath = checkPath(argv.file, argv.recursive) const index = inPath.lastIndexOf('/') + 1 const options = { diff --git a/src/cli/commands/files/get.js b/src/cli/commands/files/get.js index c177fb8719..67ba83793e 100644 --- a/src/cli/commands/files/get.js +++ b/src/cli/commands/files/get.js @@ -1,49 +1,5 @@ 'use strict' -var fs = require('fs') -const path = require('path') -const mkdirp = require('mkdirp') -const pull = require('pull-stream') -const toPull = require('stream-to-pull-stream') -const print = require('../../utils').print - -function checkArgs (hash, outPath) { - // format the output directory - if (!outPath.endsWith(path.sep)) { - outPath += path.sep - } - - return outPath -} - -function ensureDirFor (dir, file, callback) { - const lastSlash = file.path.lastIndexOf('/') - const filePath = file.path.substring(0, lastSlash + 1) - const dirPath = path.join(dir, filePath) - mkdirp(dirPath, callback) -} - -function fileHandler (dir) { - return function onFile (file, callback) { - ensureDirFor(dir, file, (err) => { - if (err) { - callback(err) - } else { - const fullFilePath = path.join(dir, file.path) - if (file.content) { - file.content - .pipe(fs.createWriteStream(fullFilePath)) - .once('error', callback) - .once('finish', callback) - } else { - // this is a dir - mkdirp(fullFilePath, callback) - } - } - }) - } -} - module.exports = { command: 'get ', @@ -58,6 +14,50 @@ module.exports = { }, handler (argv) { + var fs = require('fs') + const path = require('path') + const mkdirp = require('mkdirp') + const pull = require('pull-stream') + const toPull = require('stream-to-pull-stream') + const print = require('../../utils').print + + function checkArgs (hash, outPath) { + // format the output directory + if (!outPath.endsWith(path.sep)) { + outPath += path.sep + } + + return outPath + } + + function ensureDirFor (dir, file, callback) { + const lastSlash = file.path.lastIndexOf('/') + const filePath = file.path.substring(0, lastSlash + 1) + const dirPath = path.join(dir, filePath) + mkdirp(dirPath, callback) + } + + function fileHandler (dir) { + return function onFile (file, callback) { + ensureDirFor(dir, file, (err) => { + if (err) { + callback(err) + } else { + const fullFilePath = path.join(dir, file.path) + if (file.content) { + file.content + .pipe(fs.createWriteStream(fullFilePath)) + .once('error', callback) + .once('finish', callback) + } else { + // this is a dir + mkdirp(fullFilePath, callback) + } + } + }) + } + } + const ipfsPath = argv['ipfsPath'] const dir = checkArgs(ipfsPath, argv.output) diff --git a/src/cli/commands/id.js b/src/cli/commands/id.js index 81ed38eef4..22fba6172d 100644 --- a/src/cli/commands/id.js +++ b/src/cli/commands/id.js @@ -1,6 +1,4 @@ 'use strict' -const print = require('../utils').print - module.exports = { command: 'id', @@ -14,6 +12,8 @@ module.exports = { }, handler (argv) { + const print = require('../utils').print + // TODO: handle argv.format argv.ipfs.id((err, id) => { if (err) { diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js index 36525419b4..d69ac24a8a 100644 --- a/src/cli/commands/init.js +++ b/src/cli/commands/init.js @@ -1,7 +1,5 @@ 'use strict' -const Repo = require('ipfs-repo') -const IPFS = require('../../core') const utils = require('../utils') const print = utils.print @@ -27,6 +25,8 @@ module.exports = { }, handler (argv) { + const Repo = require('ipfs-repo') + const IPFS = require('../../core') const path = utils.getRepoPath() print(`initializing ipfs node at ${path}`) diff --git a/src/cli/commands/key/export.js b/src/cli/commands/key/export.js index 66adde248c..bcaeaf4e36 100644 --- a/src/cli/commands/key/export.js +++ b/src/cli/commands/key/export.js @@ -1,7 +1,5 @@ 'use strict' -const fs = require('fs') - module.exports = { command: 'export ', @@ -23,6 +21,8 @@ module.exports = { }, handler (argv) { + const fs = require('fs') + argv.ipfs.key.export(argv.name, argv.passout, (err, pem) => { if (err) { throw err diff --git a/src/cli/commands/key/gen.js b/src/cli/commands/key/gen.js index a3f108eeaa..1791201578 100644 --- a/src/cli/commands/key/gen.js +++ b/src/cli/commands/key/gen.js @@ -1,7 +1,5 @@ 'use strict' -const print = require('../../utils').print - module.exports = { command: 'gen ', @@ -21,6 +19,8 @@ module.exports = { }, handler (argv) { + const print = require('../../utils').print + const opts = { type: argv.type, size: argv.size diff --git a/src/cli/commands/key/import.js b/src/cli/commands/key/import.js index ae0363b25d..38dd36dff7 100644 --- a/src/cli/commands/key/import.js +++ b/src/cli/commands/key/import.js @@ -1,7 +1,6 @@ 'use strict' const fs = require('fs') -const print = require('../../utils').print module.exports = { command: 'import ', @@ -24,6 +23,8 @@ module.exports = { }, handler (argv) { + const print = require('../../utils').print + argv.ipfs.key.import(argv.name, argv.input, argv.passin, (err, key) => { if (err) { throw err diff --git a/src/cli/commands/key/list.js b/src/cli/commands/key/list.js index d50db99697..ce9a4782a0 100644 --- a/src/cli/commands/key/list.js +++ b/src/cli/commands/key/list.js @@ -1,7 +1,5 @@ 'use strict' -const print = require('../../utils').print - module.exports = { command: 'list', @@ -10,6 +8,8 @@ module.exports = { builder: {}, handler (argv) { + const print = require('../../utils').print + argv.ipfs.key.list((err, keys) => { if (err) { throw err diff --git a/src/cli/commands/key/rename.js b/src/cli/commands/key/rename.js index 9126dbbb36..0255d4775e 100644 --- a/src/cli/commands/key/rename.js +++ b/src/cli/commands/key/rename.js @@ -1,7 +1,5 @@ 'use strict' -const print = require('../../utils').print - module.exports = { command: 'rename ', @@ -10,6 +8,8 @@ module.exports = { builder: {}, handler (argv) { + const print = require('../../utils').print + argv.ipfs.key.rename(argv.name, argv.newName, (err, res) => { if (err) { throw err diff --git a/src/cli/commands/key/rm.js b/src/cli/commands/key/rm.js index a7a5daf658..962521ddac 100644 --- a/src/cli/commands/key/rm.js +++ b/src/cli/commands/key/rm.js @@ -1,7 +1,5 @@ 'use strict' -const print = require('../../utils').print - module.exports = { command: 'rm ', @@ -10,6 +8,8 @@ module.exports = { builder: {}, handler (argv) { + const print = require('../../utils').print + argv.ipfs.key.rm(argv.name, (err, key) => { if (err) { throw err diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index cf63dde2e1..5fdeba14d8 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -1,7 +1,5 @@ 'use strict' -const utils = require('../utils') - module.exports = { command: 'ls ', @@ -28,6 +26,8 @@ module.exports = { }, handler (argv) { + const utils = require('../utils') + let path = argv.key if (path.startsWith('/ipfs/')) { path = path.replace('/ipfs/', '') diff --git a/src/cli/commands/object/data.js b/src/cli/commands/object/data.js index d356e1c6c1..d0a02d2a11 100644 --- a/src/cli/commands/object/data.js +++ b/src/cli/commands/object/data.js @@ -1,7 +1,5 @@ 'use strict' -const print = require('../../utils').print - module.exports = { command: 'data ', @@ -10,6 +8,8 @@ module.exports = { builder: {}, handler (argv) { + const print = require('../../utils').print + argv.ipfs.object.data(argv.key, { enc: 'base58' }, (err, data) => { diff --git a/src/cli/commands/object/get.js b/src/cli/commands/object/get.js index 629a3a82d1..a92e981be8 100644 --- a/src/cli/commands/object/get.js +++ b/src/cli/commands/object/get.js @@ -1,7 +1,5 @@ 'use strict' -const print = require('../../utils').print - module.exports = { command: 'get ', @@ -10,6 +8,8 @@ module.exports = { builder: {}, handler (argv) { + const print = require('../../utils').print + argv.ipfs.object.get(argv.key, {enc: 'base58'}, (err, node) => { if (err) { throw err diff --git a/src/cli/commands/object/links.js b/src/cli/commands/object/links.js index d657820fb4..91962a4151 100644 --- a/src/cli/commands/object/links.js +++ b/src/cli/commands/object/links.js @@ -1,7 +1,5 @@ 'use strict' -const print = require('../../utils').print - module.exports = { command: 'links ', @@ -10,6 +8,8 @@ module.exports = { builder: {}, handler (argv) { + const print = require('../../utils').print + argv.ipfs.object.links(argv.key, { enc: 'base58' }, (err, links) => { diff --git a/src/cli/commands/object/new.js b/src/cli/commands/object/new.js index f96db85fb2..d27e3c3dec 100644 --- a/src/cli/commands/object/new.js +++ b/src/cli/commands/object/new.js @@ -1,10 +1,5 @@ 'use strict' -const debug = require('debug') -const log = debug('cli:object') -log.error = debug('cli:object:error') -const print = require('../../utils').print - module.exports = { command: 'new [