2
2
3
3
import { queue as asyncQueue , series as asyncSeries } from 'async'
4
4
import * as chalk from 'chalk'
5
- import * as program from 'commander'
5
+ import { Command } from 'commander'
6
6
import { existsSync , readFileSync , statSync } from 'fs'
7
7
import * as glob from 'glob'
8
8
import { IGlob } from 'glob'
@@ -28,6 +28,8 @@ function map(val: string) {
28
28
return objMap
29
29
}
30
30
31
+ const program = new Command ( )
32
+
31
33
program . on ( '--help' , ( ) => {
32
34
console . log ( ' Examples:' )
33
35
console . log ( '' )
@@ -76,7 +78,9 @@ program
76
78
. option ( '--warn' , 'Warn only, exit with 0' )
77
79
. parse ( process . argv )
78
80
79
- if ( program . list ) {
81
+ const cliOptions = program . opts ( )
82
+
83
+ if ( cliOptions . list ) {
80
84
listRules ( )
81
85
process . exit ( 0 )
82
86
}
@@ -88,19 +92,19 @@ if (arrTargets.length === 0) {
88
92
89
93
// init formatter
90
94
formatter . init ( HTMLHint , {
91
- nocolor : program . nocolor ,
95
+ nocolor : cliOptions . nocolor ,
92
96
} )
93
97
94
- const format = program . format || 'default'
98
+ const format = cliOptions . format || 'default'
95
99
if ( format ) {
96
100
formatter . setFormat ( format )
97
101
}
98
102
99
103
hintTargets ( arrTargets , {
100
- rulesdir : program . rulesdir ,
101
- ruleset : program . rules ,
104
+ rulesdir : cliOptions . rulesdir ,
105
+ ruleset : cliOptions . rules ,
102
106
formatter : formatter ,
103
- ignore : program . ignore ,
107
+ ignore : cliOptions . ignore ,
104
108
} )
105
109
106
110
// list all rules
@@ -170,7 +174,7 @@ function hintTargets(
170
174
allHintCount : allHintCount ,
171
175
time : spendTime ,
172
176
} )
173
- process . exit ( ! program . warn && allHintCount > 0 ? 1 : 0 )
177
+ process . exit ( ! cliOptions . warn && allHintCount > 0 ? 1 : 0 )
174
178
} )
175
179
}
176
180
@@ -244,7 +248,7 @@ function hintAllFiles(
244
248
// init ruleset
245
249
let ruleset = options . ruleset
246
250
if ( ruleset === undefined ) {
247
- ruleset = getConfig ( program . config , globInfo . base , formatter )
251
+ ruleset = getConfig ( cliOptions . config , globInfo . base , formatter )
248
252
}
249
253
250
254
// hint queue
0 commit comments