@@ -21,24 +21,25 @@ const _exit = process.exit;
21
21
// TODO: Switch to a different command framework
22
22
process . exit = exit ;
23
23
24
- let _helpShown = false ;
25
-
26
24
// CLI
27
25
28
- around ( program , 'optionMissingArgument' , ( fn , args ) => {
26
+ around ( program , 'optionMissingArgument' , function ( fn , args ) {
29
27
program . outputHelp ( ) ;
30
- fn ( ... args ) ;
28
+ fn . apply ( this , args ) ;
31
29
return { args : [ ] , unknown : [ ] } ;
32
30
} ) ;
33
31
34
- before ( program , 'outputHelp' , ( ) => {
32
+ before ( program , 'outputHelp' , function ( ) {
35
33
// track if help was shown for unknown option
36
- _helpShown = true ;
34
+ this . _helpShown = true ;
37
35
} ) ;
38
36
39
- before ( program , 'unknownOption' , ( ) => {
37
+ before ( program , 'unknownOption' , function ( ) {
38
+ // allow unknown options if help was shown, to prevent trailing error
39
+ this . _allowUnknownOption = this . _helpShown ;
40
+
40
41
// show help if not yet shown
41
- if ( ! _helpShown ) {
42
+ if ( ! this . _helpShown ) {
42
43
program . outputHelp ( ) ;
43
44
}
44
45
} ) ;
@@ -92,11 +93,11 @@ function around(obj, method, fn) {
92
93
const old = obj [ method ] ;
93
94
94
95
obj [ method ] = function ( ) {
95
- var args = new Array ( arguments . length ) ;
96
+ const args = new Array ( arguments . length ) ;
96
97
for ( let i = 0 ; i < args . length ; i ++ ) {
97
98
args [ i ] = arguments [ i ] ;
98
99
}
99
- return fn ( old , args ) ;
100
+ return fn . call ( this , old , args ) ;
100
101
} ;
101
102
}
102
103
@@ -107,9 +108,9 @@ function around(obj, method, fn) {
107
108
function before ( obj , method , fn ) {
108
109
const old = obj [ method ] ;
109
110
110
- obj [ method ] = ( ) => {
111
- fn ( ) ;
112
- old ( ... arguments ) ;
111
+ obj [ method ] = function ( ) {
112
+ fn . call ( this ) ;
113
+ old . apply ( this , arguments ) ;
113
114
} ;
114
115
}
115
116
@@ -161,7 +162,7 @@ function createApplication(name, dir) {
161
162
162
163
// Package
163
164
const pkg = {
164
- name : name ,
165
+ name,
165
166
version : '0.0.0' ,
166
167
private : true ,
167
168
scripts : {
@@ -360,7 +361,7 @@ function createApplication(name, dir) {
360
361
mkdir ( dir , 'bin' ) ;
361
362
write ( path . join ( dir , 'bin/www' ) , www . render ( ) , MODE_0755 ) ;
362
363
363
- var prompt = launchedFromCmd ( ) ? '>' : '$' ;
364
+ const prompt = launchedFromCmd ( ) ? '>' : '$' ;
364
365
365
366
if ( dir !== '.' ) {
366
367
console . log ( ) ;
@@ -501,7 +502,7 @@ function main() {
501
502
}
502
503
503
504
// Generate application
504
- emptyDirectory ( destinationPath , ( empty ) => {
505
+ emptyDirectory ( destinationPath , function ( empty ) {
505
506
if ( empty || program . force ) {
506
507
createApplication ( appName , destinationPath ) ;
507
508
} else {
@@ -560,7 +561,7 @@ function renamedOption(originalName, newName) {
560
561
561
562
function warning ( message ) {
562
563
console . error ( ) ;
563
- message . split ( '\n' ) . forEach ( ( line ) => {
564
+ message . split ( '\n' ) . forEach ( function ( line ) {
564
565
console . error ( ' warning: %s' , line ) ;
565
566
} ) ;
566
567
console . error ( ) ;
0 commit comments