Skip to content

Commit

Permalink
feat: overwriting configStore unset
Browse files Browse the repository at this point in the history
  • Loading branch information
colbymatthiassonpublic committed Jul 29, 2020
1 parent b0550f3 commit 6095dd6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,21 @@ export class Config extends ConfigFile<ConfigFile.Options> {
return this.getContents();
}

/**
* Unsets a value for a property.
*
* **Throws** *{@link SfdxError}{ name: 'UnknownConfigKey' }* If the input validator fails.
* @param key The property to unset.
*/
public unset(key: string): boolean {
const property = Config.allowedProperties.find(allowedProp => allowedProp.key === key);

if (!property) {
throw SfdxError.create('@salesforce/core', 'config', 'UnknownConfigKey', [key]);
}
return super.unset(property.key);
}

/**
* Initializer for supported config types.
*/
Expand Down
18 changes: 10 additions & 8 deletions src/config/configStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
*/

import { AsyncCreatable, set } from '@salesforce/kit';
import { AnyJson, definiteEntriesOf, definiteValuesOf, Dictionary, get, getAnyJson, JsonMap, Optional } from '@salesforce/ts-types';
import { SfdxError } from '../sfdxError';
import { Config } from './config';
import {
AnyJson,
definiteEntriesOf,
definiteValuesOf,
Dictionary,
get,
getAnyJson,
JsonMap,
Optional
} from '@salesforce/ts-types';

/**
* The allowed types stored in a config store.
Expand Down Expand Up @@ -129,11 +136,6 @@ export abstract class BaseConfigStore<T extends BaseConfigStore.Options> extends
* @param key The key.
*/
public unset(key: string): boolean {
const property = Config.getAllowedProperties().find(allowedProp => allowedProp.key === key);

if (!property) {
throw SfdxError.create('@salesforce/core', 'config', 'UnknownConfigKey', [key]);
}
return delete this.contents[key];
}

Expand Down

0 comments on commit 6095dd6

Please sign in to comment.