Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Adds quiet flags #987

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 30 additions & 3 deletions src/cli/commands/files/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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(' ')
})
Expand Down Expand Up @@ -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'
}
},

Expand Down Expand Up @@ -184,7 +211,7 @@ module.exports = {
list = [inPath]
}

addPipeline(index, addStream, list, argv.wrapWithDirectory)
addPipeline(index, addStream, list, argv)
})
})
}
Expand Down
24 changes: 24 additions & 0 deletions test/cli/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions test/cli/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down