@@ -9,15 +9,14 @@ const otplease = require('./utils/otplease.js')
99const pudding = require ( 'figgy-pudding' )
1010const relativeDate = require ( 'tiny-relative-date' )
1111const Table = require ( 'cli-table3' )
12- const usage = require ( './utils/usage.js' )
1312const 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
2221hook . 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+ )
3642function 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