@@ -11,18 +11,19 @@ import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
1111import { Duration } from '@salesforce/kit' ;
1212import {
1313 AuthFields ,
14- Aliases ,
14+ StateAggregator ,
1515 Config ,
1616 Lifecycle ,
1717 Messages ,
1818 Org ,
1919 OrgTypes ,
20+ OrgConfigProperties ,
2021 ResultEvent ,
2122 SandboxEvents ,
2223 SandboxProcessObject ,
2324 SandboxRequest ,
2425 SandboxUserAuthResponse ,
25- SfdxError ,
26+ SfError ,
2627 StatusEvent ,
2728 ScratchOrgRequest ,
2829 ScratchOrgInfo ,
@@ -114,10 +115,10 @@ export class Create extends SfdxCommand {
114115
115116 private validateSandboxFlags ( ) : void {
116117 if ( ! this . flags . targetusername ) {
117- throw SfdxError . create ( '@salesforce/plugin-org' , 'create' , ' requiresUsername') ;
118+ throw new SfError ( messages . getMessage ( ' requiresUsername') ) ;
118119 }
119120 if ( this . flags . retry !== 0 ) {
120- throw SfdxError . create ( '@salesforce/plugin-org' , 'create' , 'retryIsNotValidForSandboxes' ) ;
121+ throw new SfError ( messages . getMessage ( 'retryIsNotValidForSandboxes' ) , 'retryIsNotValidForSandboxes' ) ;
121122 }
122123
123124 if ( this . flags . clientid ) {
@@ -169,7 +170,7 @@ export class Create extends SfdxCommand {
169170 this . ux . warn ( `No SandboxName defined, generating new SandboxName: ${ sandboxReq . SandboxName } ` ) ;
170171 }
171172 if ( ! sandboxReq . LicenseType ) {
172- throw SfdxError . create ( '@salesforce/plugin-org' , 'create' , ' missingLicenseType') ;
173+ throw new SfError ( messages . getMessage ( ' missingLicenseType') ) ;
173174 }
174175 return sandboxReq ;
175176 }
@@ -201,21 +202,19 @@ export class Create extends SfdxCommand {
201202 this . ux . log ( sandboxReadyForUse ) ;
202203 this . ux . styledHeader ( 'Sandbox Org Creation Status' ) ;
203204 this . ux . table ( data , {
204- columns : [
205- { key : 'key' , label : 'Name' } ,
206- { key : 'value' , label : 'Value' } ,
207- ] ,
205+ key : { header : 'Name' } ,
206+ value : { header : 'Value' } ,
208207 } ) ;
209208 if ( results . sandboxRes ?. authUserName ) {
210209 if ( this . flags . setalias ) {
211- const alias = await Aliases . create ( Aliases . getDefaultOptions ( ) ) ;
212- alias . set ( this . flags . setalias , results . sandboxRes . authUserName ) ;
213- const result = await alias . write ( ) ;
210+ const stateAggregator = await StateAggregator . getInstance ( ) ;
211+ stateAggregator . aliases . set ( this . flags . setalias , results . sandboxRes . authUserName ) ;
212+ const result = await stateAggregator . aliases . write ( ) ;
214213 this . logger . debug ( 'Set Alias: %s result: %s' , this . flags . setalias , result ) ;
215214 }
216215 if ( this . flags . setdefaultusername ) {
217216 const globalConfig : Config = this . configAggregator . getGlobalConfig ( ) ;
218- globalConfig . set ( Config . DEFAULT_USERNAME , results . sandboxRes . authUserName ) ;
217+ globalConfig . set ( OrgConfigProperties . TARGET_ORG , results . sandboxRes . authUserName ) ;
219218 const result = await globalConfig . write ( ) ;
220219 this . logger . debug ( 'Set defaultUsername: %s result: %s' , this . flags . setdefaultusername , result ) ;
221220 }
@@ -231,18 +230,18 @@ export class Create extends SfdxCommand {
231230 return prodOrg . createSandbox ( sandboxReq , { wait } ) ;
232231 } catch ( e ) {
233232 // guaranteed to be SfdxError from core;
234- const err = e as SfdxError ;
233+ const err = e as SfError ;
235234 if ( err ?. message . includes ( 'The org cannot be found' ) ) {
236235 // there was most likely an issue with DNS when auth'ing to the new sandbox, but it was created.
237236 if ( this . flags . setalias && this . sandboxAuth ) {
238- const alias = await Aliases . create ( Aliases . getDefaultOptions ( ) ) ;
239- alias . set ( this . flags . setalias , this . sandboxAuth . authUserName ) ;
240- const result = await alias . write ( ) ;
237+ const stateAggregator = await StateAggregator . getInstance ( ) ;
238+ stateAggregator . aliases . set ( this . flags . setalias , this . sandboxAuth . authUserName ) ;
239+ const result = await stateAggregator . aliases . write ( ) ;
241240 this . logger . debug ( 'Set Alias: %s result: %s' , this . flags . setalias , result ) ;
242241 }
243242 if ( this . flags . setdefaultusername && this . sandboxAuth ) {
244243 const globalConfig : Config = this . configAggregator . getGlobalConfig ( ) ;
245- globalConfig . set ( Config . DEFAULT_USERNAME , this . sandboxAuth . authUserName ) ;
244+ globalConfig . set ( OrgConfigProperties . TARGET_ORG , this . sandboxAuth . authUserName ) ;
246245 const result = await globalConfig . write ( ) ;
247246 this . logger . debug ( 'Set defaultUsername: %s result: %s' , this . flags . setdefaultusername , result ) ;
248247 }
@@ -262,9 +261,9 @@ export class Create extends SfdxCommand {
262261 }
263262
264263 private async setAliasAndDefaultUsername ( username : string ) : Promise < void > {
265- const aliases = await Aliases . create ( Aliases . getDefaultOptions ( ) ) ;
264+ const stateAggregator = await StateAggregator . getInstance ( ) ;
266265 if ( this . flags . setalias ) {
267- await aliases . updateValue ( this . flags . setalias , username ) ;
266+ stateAggregator . aliases . set ( this . flags . setalias , username ) ;
268267 this . logger . debug ( 'Set Alias: %s result: %s' , this . flags . setalias ) ;
269268 }
270269 if ( this . flags . setdefaultusername ) {
@@ -274,20 +273,20 @@ export class Create extends SfdxCommand {
274273 } catch {
275274 config = await Config . create ( { isGlobal : true } ) ;
276275 }
277- const value = aliases . getKeysByValue ( username ) [ 0 ] || username ;
278- const result = config . set ( Config . DEFAULT_USERNAME , value ) ;
276+ const value = stateAggregator . aliases . get ( username ) || username ;
277+ const result = config . set ( OrgConfigProperties . TARGET_ORG , value ) ;
279278 await config . write ( ) ;
280279 this . logger . debug ( 'Set defaultUsername: %s result: %s' , this . flags . setdefaultusername , result ) ;
281280 }
282281 }
283282 private async createScratchOrg ( ) : Promise < ScratchOrgProcessObject > {
284283 this . logger . debug ( 'OK, will do scratch org creation' ) ;
285284 if ( ! this . hubOrg ) {
286- throw SfdxError . create ( '@salesforce/plugin-org' , 'create' , ' RequiresDevhubUsernameError') ;
285+ throw new SfError ( messages . getMessage ( ' RequiresDevhubUsernameError') ) ;
287286 }
288287 // Ensure we have an org config input source.
289288 if ( ! this . flags . definitionfile && Object . keys ( this . varargs ) . length === 0 ) {
290- throw new SfdxError ( messages . getMessage ( 'noConfig' ) ) ;
289+ throw new SfError ( messages . getMessage ( 'noConfig' ) ) ;
291290 }
292291
293292 this . logger . debug ( 'validation complete' ) ;
0 commit comments