From cfea6ea5b67ec5e4ec57e3a9cb8c82d018cb5476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Fri, 18 Jan 2019 08:43:39 -0800 Subject: [PATCH] hook: fix default usage message for npm hook --- lib/hook.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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() } }) }