@@ -9,7 +9,9 @@ class Command {
9
9
constructor ( command ) {
10
10
this . root = command . root ;
11
11
delete command . root ;
12
-
12
+ if ( command . hasOwnProperty ( 'requiresAuthentication' ) ) {
13
+ this . requiresAuthentication = command . requiresAuthentication ;
14
+ }
13
15
this . betaCommand = command . betaCommand || false ;
14
16
this . command = command ;
15
17
this . subCommands = [ ] ;
@@ -43,17 +45,25 @@ class Command {
43
45
44
46
toCommand ( ) {
45
47
let command = this . command ;
46
- //assert(_.get(this.command, "builder", true));
47
48
48
49
let funcs = _ . map ( this . builders , ( b ) => {
49
50
return ( yargs ) => {
50
51
b ( yargs ) ;
51
52
_ . forEach ( this . subCommands , ( subCommand ) => {
52
- // TODO use .toCommand here too
53
- if ( subCommand instanceof Command && ( ! subCommand . isBetaCommand ( ) || authManager . getCurrentContext ( ) . isBetaFeatEnabled ( ) ) ) {
54
- yargs . command ( subCommand . toCommand ( ) ) ;
53
+ if ( ! subCommand . hasOwnProperty ( 'requiresAuthentication' ) && command . hasOwnProperty ( 'requiresAuthentication' ) ) {
54
+ subCommand . requiresAuthentication = command . requiresAuthentication ;
55
+ } else {
56
+ subCommand . requiresAuthentication = true ;
57
+ }
58
+
59
+ if ( subCommand . isBetaCommand ( ) ) {
60
+ // load beta commands only if authentication exists and it is beta enabled
61
+ const currentContext = authManager . getCurrentContext ( ) ;
62
+ if ( currentContext && currentContext . isBetaFeatEnabled ( ) ) {
63
+ yargs . command ( subCommand . toCommand ( ) ) ;
64
+ }
55
65
} else {
56
- yargs . command ( subCommand ) ;
66
+ yargs . command ( subCommand . toCommand ( ) ) ;
57
67
}
58
68
} ) ;
59
69
return yargs ;
@@ -65,7 +75,7 @@ class Command {
65
75
} ;
66
76
67
77
command . builder = builder ;
68
- command . handler = wrapHandler ( command . handler ) ;
78
+ command . handler = wrapHandler ( command . handler , this . requiresAuthentication ) ;
69
79
return command ;
70
80
71
81
}
0 commit comments