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');
1212 */
1313exports . list = Object . keys ( commands ) ;
1414
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+ } ) ;
1522/**
1623 * Check if the command has the flag
1724 *
@@ -22,20 +29,11 @@ exports.list = Object.keys(commands);
2229 * @public
2330 */
2431exports . hasFlag = function ( commandName , flag ) {
25- var command = commands [ commandName ] ;
26- if ( ! command ) {
32+ if ( ! flags [ commandName ] ) {
2733 throw new Error ( 'Unknown command ' + commandName ) ;
2834 }
2935
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 ] ) ;
3937} ;
4038
4139/**
You can’t perform that action at this time.
0 commit comments