Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
feat(quiet): added -q/--quiet to suppress output from npx itself
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Jun 20, 2017
1 parent bec2887 commit 16607d9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ If a full specifier is included, or if `--package` is used, npx will always use

* `--ignore-existing` - If this flag is set, npx will not look in `$PATH`, or in the current package's `node_modules/.bin` for an existing version before deciding whether to install. Binaries in those paths will still be available for execution, but will be shadowed by any packages requested by this install.

* `-q, --quiet` - Suppressed any output from npx itself (progress bars, error messages, install reports). Subcommand output itself will not be silenced.

* `-v, --version` - Show the current npx version.

## EXAMPLES
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function main (argv) {
}

if (!argv.call && (!argv.command || !argv.package)) {
console.error(Y()`\nERROR: You must supply a command.\n`)
parseArgs.showHelp()
!argv.q && console.error(Y()`\nERROR: You must supply a command.\n`)
!argv.q && parseArgs.showHelp()
process.exitCode = 1
return
}
Expand Down Expand Up @@ -65,7 +65,7 @@ function main (argv) {
require('update-notifier')({pkg: require('./package.json')}).notify()
// Some npm packages need to be installed. Let's install them!
return ensurePackages(argv.package, argv).then(results => {
results && console.error(Y()`npx: installed ${
results && !argv.q && console.error(Y()`npx: installed ${
results.added.length + results.updated.length
} in ${(Date.now() - startTime) / 1000}s`)
}).then(() => existing)
Expand All @@ -85,7 +85,7 @@ function main (argv) {
}
})
}).catch(err => {
console.error(err.message)
!argv.q && console.error(err.message)
process.exitCode = err.exitCode || 1
})
})
Expand Down Expand Up @@ -168,7 +168,7 @@ function installPackages (specs, prefix, opts) {
const args = buildArgs(specs, prefix, opts)
return which(opts.npm).then(npmPath => {
return child.spawn(npmPath, args, {
stdio: [0, 'pipe', 2]
stdio: [0, 'pipe', opts.q ? 'ignore' : 2]
}).then(deets => {
try {
return deets.stdout ? JSON.parse(deets.stdout) : null
Expand Down
5 changes: 5 additions & 0 deletions parse-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ function parseArgs (argv) {
describe: Y()`Ignores existing binaries in $PATH, or in the local project. This forces npx to do a temporary install and use the latest version.`,
type: 'boolean'
})
.option('quiet', {
alias: 'q',
describe: Y()`Suppress output from npx itself. Subcommands will not be affected.`,
type: 'boolean'
})
.option('npm', {
describe: Y()`npm binary to use for internal operations.`,
type: 'string',
Expand Down

0 comments on commit 16607d9

Please sign in to comment.