File tree Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,13 @@ var commands = require('./commands');
12
12
*/
13
13
exports . list = Object . keys ( commands ) ;
14
14
15
+ var flags = { } ;
16
+ exports . list . forEach ( function ( commandName ) {
17
+ flags [ commandName ] = commands [ commandName ] . flags . reduce ( function ( flags , flag ) {
18
+ flags [ flag ] = true ;
19
+ return flags ;
20
+ } , { } ) ;
21
+ } ) ;
15
22
/**
16
23
* Check if the command has the flag
17
24
*
@@ -22,20 +29,11 @@ exports.list = Object.keys(commands);
22
29
* @public
23
30
*/
24
31
exports . hasFlag = function ( commandName , flag ) {
25
- var command = commands [ commandName ] ;
26
- if ( ! command ) {
32
+ if ( ! flags [ commandName ] ) {
27
33
throw new Error ( 'Unknown command ' + commandName ) ;
28
34
}
29
35
30
- var flags = command . flags ;
31
-
32
- for ( var i = 0 ; i < flags . length ; i ++ ) {
33
- if ( flags [ i ] === flag ) {
34
- return true ;
35
- }
36
- }
37
-
38
- return false ;
36
+ return Boolean ( flags [ commandName ] [ flag ] ) ;
39
37
} ;
40
38
41
39
/**
You can’t perform that action at this time.
0 commit comments