diff --git a/lib/hook.js b/lib/hook.js index 098d323fd2bf8..54aea9f1e9d20 100644 --- a/lib/hook.js +++ b/lib/hook.js @@ -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 [--type=]', 'npm hook ls [pkg]', 'npm hook rm ', 'npm hook update ' -]) +].join('\n') hook.completion = (opts, cb) => { validate('OF', [opts, cb]) @@ -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) @@ -46,6 +52,8 @@ function hook (args) { case 'update': case 'up': return update(args[1], args[2], args[3], opts) + default: + UsageError() } }) }