@@ -30,16 +30,18 @@ export class Set extends ConfigCommand<ConfigResponses> {
3030
3131 public async run ( ) : Promise < ConfigResponses > {
3232 const { flags } = await this . parse ( Set ) ;
33- const config : Config = await this . loadConfig ( flags . global ) ;
34- let value = '' ;
33+ const config : Config = await loadConfig ( flags . global ) ;
3534 const configs = await this . parseConfigKeysAndValues ( ) ;
3635 for ( const name of Object . keys ( configs ) ) {
36+ // We need to allow `undefined` here so that we can support unsetting with set=''
37+ // See the "use set to unset a config key" NUT
38+ const value = configs [ name ] ;
3739 try {
38- value = configs [ name ] ;
3940 // core's builtin config validation requires synchronous functions but there's
4041 // currently no way to validate an org synchronously. Therefore, we have to manually
4142 // validate the org here and manually set the error message if it fails
42- if ( this . isOrgKey ( name ) && value ) await this . validateOrg ( value ) ;
43+ // eslint-disable-next-line no-await-in-loop
44+ if ( isOrgKey ( name ) && value ) await validateOrg ( value ) ;
4345 config . set ( name , value ) ;
4446 this . responses . push ( { name, value, success : true } ) ;
4547 } catch ( err ) {
@@ -92,31 +94,29 @@ export class Set extends ConfigCommand<ConfigResponses> {
9294
9395 return configs ;
9496 }
97+ }
9598
96- protected async loadConfig ( global : boolean ) : Promise < Config > {
97- try {
98- const config = await Config . create ( Config . getDefaultOptions ( global ) ) ;
99- await config . read ( ) ;
100- return config ;
101- } catch ( error ) {
102- if ( error instanceof SfdxError ) {
103- error . actions = error . actions || [ ] ;
104- error . actions . push ( 'Run with --global to set for your entire workspace.' ) ;
105- }
106- throw error ;
99+ const loadConfig = async ( global : boolean ) : Promise < Config > => {
100+ try {
101+ const config = await Config . create ( Config . getDefaultOptions ( global ) ) ;
102+ await config . read ( ) ;
103+ return config ;
104+ } catch ( error ) {
105+ if ( error instanceof SfdxError ) {
106+ error . actions = error . actions || [ ] ;
107+ error . actions . push ( 'Run with --global to set for your entire workspace.' ) ;
107108 }
109+ throw error ;
108110 }
111+ } ;
109112
110- private isOrgKey ( name : string ) : boolean {
111- const orgKeys = [ OrgConfigProperties . TARGET_DEV_HUB , OrgConfigProperties . TARGET_ORG ] as string [ ] ;
112- return orgKeys . includes ( name ) ;
113- }
113+ const isOrgKey = ( name : string ) : boolean =>
114+ [ OrgConfigProperties . TARGET_DEV_HUB as string , OrgConfigProperties . TARGET_ORG as string ] . includes ( name ) ;
114115
115- private async validateOrg ( value : string ) : Promise < void > {
116- try {
117- await Org . create ( { aliasOrUsername : value } ) ;
118- } catch {
119- throw new Error ( `Invalid config value: org "${ value } " is not authenticated.` ) ;
120- }
116+ const validateOrg = async ( value : string ) : Promise < void > => {
117+ try {
118+ await Org . create ( { aliasOrUsername : value } ) ;
119+ } catch {
120+ throw new Error ( `Invalid config value: org "${ value } " is not authenticated.` ) ;
121121 }
122- }
122+ } ;
0 commit comments