Skip to content

Commit 2a3fa61

Browse files
committed
feat(options): add --silent flag and option for squelching output
1 parent 34a6a4e commit 2a3fa61

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

cli.js

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ var argv = require('yargs')
3838
default: defaults.noVerify,
3939
global: true
4040
})
41+
.option('silent', {
42+
describe: 'Don\'t print logs and errors',
43+
type: 'boolean',
44+
default: defaults.silent,
45+
global: true
46+
})
4147
.help()
4248
.alias('help', 'h')
4349
.example('$0', 'Update changelog and tag release')

defaults.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
"firstRelease": false,
55
"sign": false,
66
"noVerify": false,
7+
"silent": false
78
}

index.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,20 @@ function createIfMissing (argv) {
143143
}
144144

145145
function checkpoint (argv, msg, args, figure) {
146-
console.info((figure || chalk.green(figures.tick)) + ' ' + util.format.apply(util, [msg].concat(args.map(function (arg) {
147-
return chalk.bold(arg)
148-
}))))
146+
if (!argv.silent) {
147+
console.info((figure || chalk.green(figures.tick)) + ' ' + util.format.apply(util, [msg].concat(args.map(function (arg) {
148+
return chalk.bold(arg)
149+
}))))
150+
}
149151
}
150152

151153
function printError (argv, msg, opts) {
152-
opts = objectAssign({
153-
level: 'error',
154-
color: 'red'
155-
}, opts)
154+
if (!argv.silent) {
155+
opts = objectAssign({
156+
level: 'error',
157+
color: 'red'
158+
}, opts)
156159

157-
console[opts.level](chalk[opts.color](msg))
160+
console[opts.level](chalk[opts.color](msg))
161+
}
158162
}

test.js

+7
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ describe('cli', function () {
199199
execCli('-n').code.should.equal(0)
200200
})
201201

202+
it('does not print output when the --silent flag is passed', function () {
203+
var result = execCli('--silent')
204+
result.code.should.equal(0)
205+
result.stdout.should.equal('')
206+
result.stderr.should.equal('')
207+
})
208+
202209
it('does not display `npm publish` if the package is private', function () {
203210
writePackageJson('1.0.0', {private: true})
204211

0 commit comments

Comments
 (0)