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

Commit d21b492

Browse files
bmordandaviddias
authored andcommitted
feat: adds quiet flags (#1001)
1 parent 62ff8fc commit d21b492

File tree

4 files changed

+60
-9
lines changed

4 files changed

+60
-9
lines changed

src/cli/bin.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ updateNotifier({
1515
}).notify()
1616

1717
const cli = yargs
18-
.option('q', {
19-
alias: 'quiet',
20-
desc: 'suppress output',
18+
.option('silent', {
19+
desc: 'Write no output',
2120
type: 'boolean',
22-
coerce: (quiet) => { if (quiet) { utils.disablePrinting() } }
21+
default: false,
22+
coerce: ('silent', silent => silent ? utils.disablePrinting() : silent)
2323
})
2424
.commandDir('commands')
2525
.demandCommand(1)

src/cli/commands/files/add.js

+30-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ function checkPath (inPath, recursive) {
4040
return inPath
4141
}
4242

43-
function addPipeline (index, addStream, list, wrapWithDirectory) {
43+
function addPipeline (index, addStream, list, argv) {
44+
const {
45+
wrapWithDirectory,
46+
quiet,
47+
quieter,
48+
silent
49+
} = argv
50+
4451
pull(
4552
zip(
4653
pull.values(list),
@@ -72,12 +79,15 @@ function addPipeline (index, addStream, list, wrapWithDirectory) {
7279
throw err
7380
}
7481

82+
if (silent) return
83+
if (quieter) return print(added.pop().hash)
84+
7585
sortBy(added, 'path')
7686
.reverse()
7787
.map((file) => {
7888
const log = [ 'added', file.hash ]
7989

80-
if (file.path.length > 0) log.push(file.path)
90+
if (!quiet && file.path.length > 0) log.push(file.path)
8191

8292
return log.join(' ')
8393
})
@@ -124,6 +134,23 @@ module.exports = {
124134
'cid-version': {
125135
type: 'integer',
126136
describe: 'Cid version. Non-zero value will change default of \'raw-leaves\' to true. (experimental)'
137+
},
138+
quiet: {
139+
alias: 'q',
140+
type: 'boolean',
141+
default: false,
142+
describe: 'Write minimal output'
143+
},
144+
quieter: {
145+
alias: 'Q',
146+
type: 'boolean',
147+
default: false,
148+
describe: 'Write only final hash'
149+
},
150+
silent: {
151+
type: 'boolean',
152+
default: false,
153+
describe: 'Write no output'
127154
}
128155
},
129156

@@ -184,7 +211,7 @@ module.exports = {
184211
list = [inPath]
185212
}
186213

187-
addPipeline(index, addStream, list, argv.wrapWithDirectory)
214+
addPipeline(index, addStream, list, argv)
188215
})
189216
})
190217
}

test/cli/files.js

+24
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,30 @@ describe('files', () => runOnAndOff((thing) => {
198198
})
199199
})
200200

201+
it('add --quiet', () => {
202+
return ipfs('files add -q src/init-files/init-docs/readme')
203+
.then((out) => {
204+
expect(out)
205+
.to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB\n')
206+
})
207+
})
208+
209+
it('add --quieter', () => {
210+
return ipfs('files add -Q -w test/test-data/hello test/test-data/node.json')
211+
.then((out) => {
212+
expect(out)
213+
.to.eql('QmYRMUVULBfj7WrdPESnwnyZmtayN6Sdrwh1nKcQ9QgQeZ\n')
214+
})
215+
})
216+
217+
it('add --silent', () => {
218+
return ipfs('files add --silent src/init-files/init-docs/readme')
219+
.then((out) => {
220+
expect(out)
221+
.to.eql('')
222+
})
223+
})
224+
201225
it('cat', () => {
202226
return ipfs('files cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
203227
.then((out) => {

test/cli/general.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const expect = require('chai').expect
55
const runOnAndOff = require('../utils/on-and-off')
66

77
describe('general cli options', () => runOnAndOff.off((thing) => {
8-
it('should handle --quiet flag', () => {
9-
return thing.ipfs('help --quiet').then((out) => {
8+
it('should handle --silent flag', () => {
9+
return thing.ipfs('help --silent').then((out) => {
1010
expect(out).to.be.empty()
1111
})
1212
})

0 commit comments

Comments
 (0)