@@ -32,6 +32,7 @@ export class BaseCommand<O = any, A extends Array<any> = any> {
32
32
// protected name: string = location.pathname.split( '/' ).pop() as string;
33
33
protected _name : string = 'COMMAND' ;
34
34
protected _parent ?: BaseCommand ;
35
+ protected _globalParent ?: BaseCommand ;
35
36
protected ver : string = '0.0.0' ;
36
37
protected desc : IDescription = '' ;
37
38
protected fn : IAction < O , A > | undefined ;
@@ -544,6 +545,7 @@ export class BaseCommand<O = any, A extends Array<any> = any> {
544
545
const subCommand = this . rawArgs . length > 0 && this . getCommand ( this . rawArgs [ 0 ] , true ) ;
545
546
546
547
if ( subCommand ) {
548
+ subCommand . _globalParent = this ;
547
549
return await subCommand . parse ( this . rawArgs . slice ( 1 ) , dry ) ;
548
550
}
549
551
@@ -612,6 +614,8 @@ export class BaseCommand<O = any, A extends Array<any> = any> {
612
614
throw this . error ( new Error ( `Default command '${ this . defaultCommand } ' not found.` ) ) ;
613
615
}
614
616
617
+ cmd . _globalParent = this ;
618
+
615
619
try {
616
620
await cmd . execute ( options , ...args ) ;
617
621
} catch ( e ) {
@@ -821,12 +825,21 @@ export class BaseCommand<O = any, A extends Array<any> = any> {
821
825
}
822
826
823
827
/**
824
- * Get parent command name .
828
+ * Get parent command.
825
829
*/
826
830
public getParent ( ) : BaseCommand | undefined {
827
831
return this . _parent ;
828
832
}
829
833
834
+ /**
835
+ * Get parent command from global executed command.
836
+ * Be sure, to call this method only inside an action handler. Unless this or any child command was executed,
837
+ * this method returns always undefined.
838
+ */
839
+ public getGlobalParent ( ) : BaseCommand | undefined {
840
+ return this . _globalParent ;
841
+ }
842
+
830
843
/**
831
844
* Get main command.
832
845
*/
0 commit comments