@@ -15,7 +15,6 @@ import {
1515} from '@salesforce/sf-plugins-core' ;
1616import {
1717 SfError ,
18- Config ,
1918 Lifecycle ,
2019 Messages ,
2120 OrgTypes ,
@@ -79,9 +78,11 @@ export class OrgCloneCommand extends SfCommand<SandboxProcessObject> {
7978 loglevel,
8079 } ;
8180
81+ private logger ! : Logger ;
82+
8283 public async run ( ) : Promise < SandboxProcessObject > {
8384 const { flags, args, argv } = await this . parse ( OrgCloneCommand ) ;
84- const logger = await Logger . child ( this . constructor . name ) ;
85+ this . logger = await Logger . child ( this . constructor . name ) ;
8586 const varargs = parseVarArgs ( args , argv as string [ ] ) ;
8687
8788 const lifecycle = Lifecycle . getInstance ( ) ;
@@ -105,24 +106,19 @@ export class OrgCloneCommand extends SfCommand<SandboxProcessObject> {
105106 } ) ;
106107
107108 if ( results ?. sandboxRes ?. authUserName ) {
108- if ( flags . setalias ) {
109- const stateAggregator = await StateAggregator . getInstance ( ) ;
110- stateAggregator . aliases . set ( flags . setalias , results . sandboxRes . authUserName ) ;
111- const result = stateAggregator . aliases . getAll ( ) ;
112- logger . debug ( 'Set Alias: %s result: %s' , flags . setalias , result ) ;
113- }
114- if ( flags . setdefaultusername ) {
115- const globalConfig : Config = this . configAggregator . getGlobalConfig ( ) ;
116- globalConfig . set ( OrgConfigProperties . TARGET_ORG , results . sandboxRes . authUserName ) ;
117- const result = await globalConfig . write ( ) ;
118- logger . debug ( 'Set defaultUsername: %s result: %s' , flags . setdefaultusername , result ) ;
119- }
109+ if ( flags . setalias ) await this . setAlias ( flags . setalias , results . sandboxRes . authUserName ) ;
110+ if ( flags . setdefaultusername ) await this . setDefaultUsername ( results . sandboxRes . authUserName ) ;
120111 }
121112 } ) ;
122113
123- const { sandboxReq, srcSandboxName } = await createSandboxRequest ( true , flags . definitionfile , logger , varargs ) ;
114+ const { sandboxReq, srcSandboxName } = await createSandboxRequest (
115+ true ,
116+ flags . definitionfile ,
117+ this . logger ,
118+ varargs
119+ ) ;
124120
125- logger . debug ( 'Calling clone with SandboxRequest: %s and SandboxName: %s ' , sandboxReq , srcSandboxName ) ;
121+ this . logger . debug ( 'Calling clone with SandboxRequest: %s and SandboxName: %s ' , sandboxReq , srcSandboxName ) ;
126122 flags [ 'target-org' ] . getConnection ( flags [ 'api-version' ] ) ;
127123 return flags [ 'target-org' ] . cloneSandbox ( sandboxReq , srcSandboxName , { wait : flags . wait } ) ;
128124 } else {
@@ -132,4 +128,18 @@ export class OrgCloneCommand extends SfCommand<SandboxProcessObject> {
132128 ) ;
133129 }
134130 }
131+
132+ public async setAlias ( alias : string , username : string ) : Promise < void > {
133+ const stateAggregator = await StateAggregator . getInstance ( ) ;
134+ stateAggregator . aliases . set ( alias , username ) ;
135+ const result = stateAggregator . aliases . getAll ( ) ;
136+ this . logger . debug ( 'Set Alias: %s result: %s' , alias , result ) ;
137+ }
138+
139+ public async setDefaultUsername ( username : string ) : Promise < void > {
140+ const globalConfig = this . configAggregator . getGlobalConfig ( ) ;
141+ globalConfig . set ( OrgConfigProperties . TARGET_ORG , username ) ;
142+ const result = await globalConfig . write ( ) ;
143+ this . logger . debug ( 'Set defaultUsername: %s result: %s' , username , result ) ;
144+ }
135145}
0 commit comments