Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 2aac9b5

Browse files
authored
Adding command config:remove (#1160)
* Adding command config:remove * Adding missing flag description
1 parent 5c5c684 commit 2aac9b5

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*!
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import {Command, flags} from '@microsoft/bf-cli-command'
7+
import {getConfigFile, writeConfigFile, Config} from './../../utils/configfilehandler'
8+
9+
export default class ConfigRemove extends Command {
10+
static description = 'Removes the specified key from the config file'
11+
12+
static flags: flags.Input<any> = {
13+
help: flags.help({char: 'h', description: 'config:remove help'}),
14+
key: flags.string({char: 'k', description: 'Name of the key to remove', required: true}),
15+
}
16+
17+
async run() {
18+
const {flags} = this.parse(ConfigRemove)
19+
let userConfig: Config = await getConfigFile(this.config.configDir)
20+
if (userConfig[flags.key]) {
21+
delete userConfig[flags.key]
22+
await writeConfigFile(this.config.configDir, userConfig)
23+
}
24+
this.log(`${flags.key} deleted`)
25+
}
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {expect, test} from '@oclif/test'
2+
import {initTestConfigFile, deleteTestConfigFile, getConfigFile} from './../../configfilehelper'
3+
4+
const fs = require('fs-extra')
5+
6+
describe('config:remove', () => {
7+
before(async function() {
8+
await initTestConfigFile()
9+
});
10+
11+
after(async function() {
12+
await deleteTestConfigFile()
13+
});
14+
15+
test
16+
.stdout()
17+
.command(['config:set', '--key', 'a', '--value', 'b'])
18+
.it('Adds a value in config file', async ctx => {
19+
let config = await fs.readJSON(getConfigFile())
20+
expect(config.a).to.contain('b')
21+
})
22+
23+
test
24+
.stdout()
25+
.command(['config:remove', '--key', 'a'])
26+
.it('Removes value from config file', async ctx => {
27+
let config = await fs.readJSON(getConfigFile())
28+
expect(config.a).to.equal(undefined)
29+
})
30+
})

0 commit comments

Comments
 (0)