Skip to content

Commit cfea6ea

Browse files
committed
hook: fix default usage message for npm hook
1 parent 8543fc3 commit cfea6ea

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/hook.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ const otplease = require('./utils/otplease.js')
99
const pudding = require('figgy-pudding')
1010
const relativeDate = require('tiny-relative-date')
1111
const Table = require('cli-table3')
12-
const usage = require('./utils/usage.js')
1312
const validate = require('aproba')
1413

15-
hook.usage = usage([
14+
hook.usage = [
1615
'npm hook add <pkg> <url> <secret> [--type=<type>]',
1716
'npm hook ls [pkg]',
1817
'npm hook rm <id>',
1918
'npm hook update <id> <url> <secret>'
20-
])
19+
].join('\n')
2120

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

35-
module.exports = (args, cb) => BB.try(() => hook(args)).nodeify(cb)
34+
function UsageError () {
35+
throw Object.assign(new Error(hook.usage), {code: 'EUSAGE'})
36+
}
37+
38+
module.exports = (args, cb) => BB.try(() => hook(args)).then(
39+
val => cb(null, val),
40+
err => err.code === 'EUSAGE' ? cb(err.message) : cb(err)
41+
)
3642
function hook (args) {
3743
return otplease(npmConfig(), opts => {
3844
opts = HookConfig(opts)
@@ -46,6 +52,8 @@ function hook (args) {
4652
case 'update':
4753
case 'up':
4854
return update(args[1], args[2], args[3], opts)
55+
default:
56+
UsageError()
4957
}
5058
})
5159
}

0 commit comments

Comments
 (0)