This repository has been archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding config:set command and standardizing set behavior (#542)
* Adding command to add keys and values to config file * Adding flag to specify a key to show * Removing prompting from set:luis * Fixing config README.md
- Loading branch information
1 parent
6207a61
commit 353ac80
Showing
7 changed files
with
153 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import {Command, flags} from '@microsoft/bf-cli-command' | ||
import {getConfigFile, writeConfigFile, Config} from './../../utils/configfilehandler' | ||
|
||
export default class ConfigSet extends Command { | ||
static description = 'Adds the specified key and value to the config file' | ||
|
||
static flags: flags.Input<any> = { | ||
key: flags.string({char: 'k', description: 'Name of the key to add or override', required: true}), | ||
value: flags.string({char: 'v', description: 'Value associated with the specified key', required: true}), | ||
help: flags.help({char: 'h', description: 'config:set help'}) | ||
} | ||
|
||
async run() { | ||
const {flags} = this.parse(ConfigSet) | ||
let userConfig: Config = await getConfigFile(this.config.configDir) | ||
userConfig[flags.key] = flags.value | ||
await writeConfigFile(this.config.configDir, userConfig) | ||
this.log(`${flags.key} set to ${flags.value}`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {expect, test} from '@oclif/test' | ||
import {initTestConfigFile, deleteTestConfigFile, getConfigFile} from './../../configfilehelper' | ||
|
||
const fs = require('fs-extra') | ||
|
||
describe('config:set', () => { | ||
before(async function() { | ||
await initTestConfigFile() | ||
}); | ||
|
||
after(async function() { | ||
await deleteTestConfigFile() | ||
}); | ||
|
||
test | ||
.stdout() | ||
.command(['config:set', '--key', 'a', '--value', 'b']) | ||
.it('Adds a value in config file', async ctx => { | ||
let config = await fs.readJSON(getConfigFile()) | ||
expect(config.a).to.contain('b') | ||
}) | ||
|
||
test | ||
.stdout() | ||
.command(['config:set', '--key', 'a', '--value', 'c']) | ||
.it('Modifies a value in config file', async ctx => { | ||
let config = await fs.readJSON(getConfigFile()) | ||
expect(config.a).to.contain('c') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters