Skip to content

Commit

Permalink
feat(options): add --silent flag and option for squelching output
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapppi committed Sep 27, 2016
1 parent 34a6a4e commit 2a3fa61
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
6 changes: 6 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ var argv = require('yargs')
default: defaults.noVerify,
global: true
})
.option('silent', {
describe: 'Don\'t print logs and errors',
type: 'boolean',
default: defaults.silent,
global: true
})
.help()
.alias('help', 'h')
.example('$0', 'Update changelog and tag release')
Expand Down
1 change: 1 addition & 0 deletions defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
"firstRelease": false,
"sign": false,
"noVerify": false,
"silent": false
}
20 changes: 12 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,20 @@ function createIfMissing (argv) {
}

function checkpoint (argv, msg, args, figure) {
console.info((figure || chalk.green(figures.tick)) + ' ' + util.format.apply(util, [msg].concat(args.map(function (arg) {
return chalk.bold(arg)
}))))
if (!argv.silent) {
console.info((figure || chalk.green(figures.tick)) + ' ' + util.format.apply(util, [msg].concat(args.map(function (arg) {
return chalk.bold(arg)
}))))
}
}

function printError (argv, msg, opts) {
opts = objectAssign({
level: 'error',
color: 'red'
}, opts)
if (!argv.silent) {
opts = objectAssign({
level: 'error',
color: 'red'
}, opts)

console[opts.level](chalk[opts.color](msg))
console[opts.level](chalk[opts.color](msg))
}
}
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ describe('cli', function () {
execCli('-n').code.should.equal(0)
})

it('does not print output when the --silent flag is passed', function () {
var result = execCli('--silent')
result.code.should.equal(0)
result.stdout.should.equal('')
result.stderr.should.equal('')
})

it('does not display `npm publish` if the package is private', function () {
writePackageJson('1.0.0', {private: true})

Expand Down

0 comments on commit 2a3fa61

Please sign in to comment.