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 exists
1724 *
@@ -33,20 +40,11 @@ exports.exists = function (commandName) {
3340 * @public
3441 */
3542exports . hasFlag = function ( commandName , flag ) {
36- var command = commands [ commandName ] ;
37- if ( ! command ) {
43+ if ( ! flags [ commandName ] ) {
3844 throw new Error ( 'Unknown command ' + commandName ) ;
3945 }
4046
41- var flags = command . flags ;
42-
43- for ( var i = 0 ; i < flags . length ; i ++ ) {
44- if ( flags [ i ] === flag ) {
45- return true ;
46- }
47- }
48-
49- return false ;
47+ return Boolean ( flags [ commandName ] [ flag ] ) ;
5048} ;
5149
5250/**
You can’t perform that action at this time.
0 commit comments