Skip to content

Commit

Permalink
feat(update): Calling updater-notifier automatically if there is pack…
Browse files Browse the repository at this point in the history
…age information

closes #2
  • Loading branch information
bahmutov committed Dec 3, 2015
1 parent f6ef63d commit 92d9936
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ require('simple-bin-help')(options);
If `noExit` is true, the call simply shows the error message if number of arguments is
invalid and returns a boolean result.

## Bonus features

Includes and calls the [update-notifier]() module by default.

### Small print

Author: Gleb Bahmutov © 2015
Expand Down
21 changes: 18 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict'

const updateNotifier = require('update-notifier')

function noArguments (minLength, args) {
console.assert(Array.isArray(args), 'missing arguments')
return args.length < minLength
}

function showHelp (options) {
var helpMessage = options.help || options.helpMessage

function getPackage (options) {
var pkg

if (options.package) {
Expand All @@ -14,6 +16,14 @@ function showHelp (options) {
pkg = require(options.packagePath)
}

return pkg
}

function showHelp (options) {
var helpMessage = options.help || options.helpMessage

var pkg = getPackage(options)

var pkgInfo
if (pkg) {
pkgInfo = pkg.name + '@' + pkg.version + '\n - ' + pkg.description
Expand All @@ -40,6 +50,11 @@ function simpleBinHelp (options, cliArguments) {
cliArguments = process.argv
}

var pkg = getPackage(options)
if (pkg) {
updateNotifier({ pkg: pkg }).notify()
}

var minArguments = options.minArguments ||
options.min ||
options.n
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@
"post-commit": [],
"post-merge": []
}
},
"dependencies": {
"update-notifier": "0.5.0"
}
}

0 comments on commit 92d9936

Please sign in to comment.