File tree Expand file tree Collapse file tree 3 files changed +39
-24
lines changed Expand file tree Collapse file tree 3 files changed +39
-24
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env node
2
2
3
- var program = require ( 'commander' ) ;
4
3
var cli = require ( '../lib/cli' ) ;
5
-
6
- program
7
- . version ( require ( '../package.json' ) . version )
8
- . usage ( '[options]' )
9
- . description ( 'A tool to manage project Git hooks' )
10
- . option ( '--install' , 'Replace existing hooks in this repository with a call git-hooks. Move old hooks directory to hooks.old' )
11
- . option ( '--uninstall' , 'Remove existing hooks in this repository and rename hooks.old back to hooks' )
12
- . parse ( process . argv ) ;
13
-
14
- cli ( program ) ;
4
+ cli ( process . argv [ 2 ] ) ;
Original file line number Diff line number Diff line change 1
1
var gitHooks = require ( '../lib/git-hooks' ) ;
2
+ var options = {
3
+ help : 'Output usage information' ,
4
+ version : 'Output the version number' ,
5
+ install : 'Replace existing hooks in this repository with a call git-hooks. Move old hooks directory to hooks.old' ,
6
+ uninstall : 'Remove existing hooks in this repository and rename hooks.old back to hooks'
7
+ } ;
2
8
3
- module . exports = function ( program ) {
4
- var command = program . install && 'install' || program . uninstall && 'uninstall' ;
5
-
6
- if ( ! gitHooks [ command ] ) {
7
- return program . outputHelp ( ) ;
8
- }
9
+ module . exports = function ( command ) {
10
+ command = command && command . replace ( / - / g, '' ) ;
9
11
10
- try {
11
- gitHooks [ command ] ( ) ;
12
- } catch ( e ) {
13
- console . error ( e . message ) ;
12
+ switch ( command ) {
13
+ case 'version' :
14
+ console . log ( require ( '../package.json' ) . version ) ;
15
+ break ;
16
+ case 'install' :
17
+ case 'uninstall' :
18
+ try {
19
+ gitHooks [ command ] ( ) ;
20
+ } catch ( e ) {
21
+ console . error ( e . message ) ;
22
+ }
23
+ break ;
24
+ default :
25
+ outputHelp ( ) ;
14
26
}
15
27
} ;
28
+
29
+ /**
30
+ * Outputs the help to console.
31
+ */
32
+ function outputHelp ( ) {
33
+ console . log (
34
+ '\nUsage: git-hooks [options]\n\n' +
35
+ 'A tool to manage project Git hooks\n\n' +
36
+ 'Options:\n\n' +
37
+ Object . keys ( options )
38
+ . map ( function ( key ) {
39
+ return ' --' + key + '\t' + options [ key ] + '\n' ;
40
+ } )
41
+ . join ( '' )
42
+ ) ;
43
+ }
Original file line number Diff line number Diff line change 18
18
" examples" ,
19
19
" lib"
20
20
],
21
- "dependencies" : {
22
- "commander" : " ^2.8.1"
23
- },
24
21
"devDependencies" : {
25
22
"chai" : " ^2.3.0" ,
26
23
"jscs" : " ^1.13.1" ,
You can’t perform that action at this time.
0 commit comments