@@ -9,15 +9,14 @@ const otplease = require('./utils/otplease.js')
9
9
const pudding = require ( 'figgy-pudding' )
10
10
const relativeDate = require ( 'tiny-relative-date' )
11
11
const Table = require ( 'cli-table3' )
12
- const usage = require ( './utils/usage.js' )
13
12
const validate = require ( 'aproba' )
14
13
15
- hook . usage = usage ( [
14
+ hook . usage = [
16
15
'npm hook add <pkg> <url> <secret> [--type=<type>]' ,
17
16
'npm hook ls [pkg]' ,
18
17
'npm hook rm <id>' ,
19
18
'npm hook update <id> <url> <secret>'
20
- ] )
19
+ ] . join ( '\n' )
21
20
22
21
hook . completion = ( opts , cb ) => {
23
22
validate ( 'OF' , [ opts , cb ] )
@@ -32,7 +31,14 @@ const HookConfig = pudding({
32
31
unicode : { }
33
32
} )
34
33
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
+ )
36
42
function hook ( args ) {
37
43
return otplease ( npmConfig ( ) , opts => {
38
44
opts = HookConfig ( opts )
@@ -46,6 +52,8 @@ function hook (args) {
46
52
case 'update' :
47
53
case 'up' :
48
54
return update ( args [ 1 ] , args [ 2 ] , args [ 3 ] , opts )
55
+ default :
56
+ UsageError ( )
49
57
}
50
58
} )
51
59
}
0 commit comments