From d8d0f5f6a7dbad08dc1758bdd72eba95c79eda34 Mon Sep 17 00:00:00 2001 From: Bernard Mordan Date: Mon, 4 Sep 2017 13:18:11 +0100 Subject: [PATCH] adds quiet flags --- src/cli/bin.js | 8 ++++---- src/cli/commands/files/add.js | 33 ++++++++++++++++++++++++++++++--- test/cli/files.js | 24 ++++++++++++++++++++++++ test/cli/general.js | 4 ++-- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/cli/bin.js b/src/cli/bin.js index 8da1473cdd..c9a72f2aa1 100755 --- a/src/cli/bin.js +++ b/src/cli/bin.js @@ -15,11 +15,11 @@ updateNotifier({ }).notify() const cli = yargs - .option('q', { - alias: 'quiet', - desc: 'suppress output', + .option('silent', { + desc: 'Write no output', type: 'boolean', - coerce: (quiet) => { if (quiet) { utils.disablePrinting() } } + default: false, + coerce: ('silent', silent => silent ? utils.disablePrinting() : silent) }) .commandDir('commands') .demandCommand(1) diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index a28c9c1fb3..82fe7ecb18 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -40,7 +40,14 @@ function checkPath (inPath, recursive) { return inPath } -function addPipeline (index, addStream, list, wrapWithDirectory) { +function addPipeline (index, addStream, list, argv) { + const { + wrapWithDirectory, + quiet, + quieter, + silent + } = argv + pull( zip( pull.values(list), @@ -72,12 +79,15 @@ function addPipeline (index, addStream, list, wrapWithDirectory) { throw err } + if (silent) return + if (quieter) return print(added.pop().hash) + sortBy(added, 'path') .reverse() .map((file) => { const log = [ 'added', file.hash ] - if (file.path.length > 0) log.push(file.path) + if (!quiet && file.path.length > 0) log.push(file.path) return log.join(' ') }) @@ -124,6 +134,23 @@ module.exports = { 'cid-version': { type: 'integer', describe: 'Cid version. Non-zero value will change default of \'raw-leaves\' to true. (experimental)' + }, + quiet: { + alias: 'q', + type: 'boolean', + default: false, + describe: 'Write minimal output' + }, + quieter: { + alias: 'Q', + type: 'boolean', + default: false, + describe: 'Write only final hash' + }, + silent: { + type: 'boolean', + default: false, + describe: 'Write no output' } }, @@ -184,7 +211,7 @@ module.exports = { list = [inPath] } - addPipeline(index, addStream, list, argv.wrapWithDirectory) + addPipeline(index, addStream, list, argv) }) }) } diff --git a/test/cli/files.js b/test/cli/files.js index b7030ebc3d..85f7fbd9b4 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -198,6 +198,30 @@ describe('files', () => runOnAndOff((thing) => { }) }) + it('add --quiet', () => { + return ipfs('files add -q src/init-files/init-docs/readme') + .then((out) => { + expect(out) + .to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB\n') + }) + }) + + it('add --quieter', () => { + return ipfs('files add -Q -w test/test-data/hello test/test-data/node.json') + .then((out) => { + expect(out) + .to.eql('QmYRMUVULBfj7WrdPESnwnyZmtayN6Sdrwh1nKcQ9QgQeZ\n') + }) + }) + + it('add --silent', () => { + return ipfs('files add --silent src/init-files/init-docs/readme') + .then((out) => { + expect(out) + .to.eql('') + }) + }) + it('cat', () => { return ipfs('files cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') .then((out) => { diff --git a/test/cli/general.js b/test/cli/general.js index fceac23052..5a36e1529b 100644 --- a/test/cli/general.js +++ b/test/cli/general.js @@ -5,8 +5,8 @@ const expect = require('chai').expect const runOnAndOff = require('../utils/on-and-off') describe('general cli options', () => runOnAndOff.off((thing) => { - it('should handle --quiet flag', () => { - return thing.ipfs('help --quiet').then((out) => { + it('should handle --silent flag', () => { + return thing.ipfs('help --silent').then((out) => { expect(out).to.be.empty() }) })