Skip to content

Commit

Permalink
hook: fix default usage message for npm hook
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Jan 18, 2019
1 parent 8543fc3 commit cfea6ea
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ const otplease = require('./utils/otplease.js')
const pudding = require('figgy-pudding')
const relativeDate = require('tiny-relative-date')
const Table = require('cli-table3')
const usage = require('./utils/usage.js')
const validate = require('aproba')

hook.usage = usage([
hook.usage = [
'npm hook add <pkg> <url> <secret> [--type=<type>]',
'npm hook ls [pkg]',
'npm hook rm <id>',
'npm hook update <id> <url> <secret>'
])
].join('\n')

hook.completion = (opts, cb) => {
validate('OF', [opts, cb])
Expand All @@ -32,7 +31,14 @@ const HookConfig = pudding({
unicode: {}
})

module.exports = (args, cb) => BB.try(() => hook(args)).nodeify(cb)
function UsageError () {
throw Object.assign(new Error(hook.usage), {code: 'EUSAGE'})
}

module.exports = (args, cb) => BB.try(() => hook(args)).then(
val => cb(null, val),
err => err.code === 'EUSAGE' ? cb(err.message) : cb(err)
)
function hook (args) {
return otplease(npmConfig(), opts => {
opts = HookConfig(opts)
Expand All @@ -46,6 +52,8 @@ function hook (args) {
case 'update':
case 'up':
return update(args[1], args[2], args[3], opts)
default:
UsageError()
}
})
}
Expand Down

0 comments on commit cfea6ea

Please sign in to comment.