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

Commit 72a7369

Browse files
JSprumunozemilio
authored andcommitted
Various qa fixes (#427)
1 parent 3865a82 commit 72a7369

File tree

20 files changed

+119
-96
lines changed

20 files changed

+119
-96
lines changed

packages/luis/src/commands/luis/init.ts renamed to packages/config/src/commands/config/set/luis.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
* Licensed under the MIT License.
44
*/
55

6-
import {CLIError, Command, flags} from '@microsoft/bf-cli-command'
7-
import { throws } from 'assert'
6+
import {Command, flags} from '@microsoft/bf-cli-command'
87
const {cli} = require('cli-ux')
9-
const utils = require('../../utils/index')
8+
import {getConfigFile, writeConfigFile, Config} from '../../../utils/configfilehandler'
109

11-
export default class LuisInit extends Command {
10+
export default class ConfigSetLuis extends Command {
1211
static description = 'Stores default LUIS application values in global config.'
1312

1413
static examples = [`
@@ -24,7 +23,7 @@ export default class LuisInit extends Command {
2423
}
2524

2625
async run() {
27-
const {flags} = this.parse(LuisInit)
26+
const {flags} = this.parse(ConfigSetLuis)
2827
const configDir = this.config.configDir
2928

3029
if (Object.entries(flags).length === 0 && flags.constructor === Object) {
@@ -37,24 +36,20 @@ export default class LuisInit extends Command {
3736
return this.log('Unable to save config settings')
3837
} catch (err) {
3938
this.log(`Unable to save config settings: ${err}`)
39+
this._help()
4040
}
4141
}
4242

4343
async promptSaveConfig(flags: any, configPath: string) {
4444
const configPrefix = 'luis__'
45-
let userConfig = await utils.getUserConfig(configPath)
46-
if (userConfig === null) {
47-
await utils.createConfigFile(configPath)
48-
userConfig = {}
49-
}
45+
let userConfig: Config = await getConfigFile(configPath)
5046
const saveConfigOptIn = await cli.confirm('Would you like to save the provided values to your global config file? (Y/N)')
5147
if (saveConfigOptIn) {
52-
// save config
5348
const flagLabels = Object.keys(flags)
5449
flagLabels.map(label => {
5550
userConfig[`${configPrefix}${label}`] = flags[label]
5651
})
57-
await utils.writeUserConfig(userConfig, configPath)
52+
await writeConfigFile(configPath, userConfig)
5853
return true
5954
}
6055
return false

packages/config/src/commands/config/set/qnamaker.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export default class ConfigSetQnamaker extends Command {
2929
async run() {
3030
const {flags} = this.parse(ConfigSetQnamaker)
3131
let userConfig: Config = await getConfigFile(this.config.configDir)
32-
3332
if (flags.subscriptionKey) {
3433
this.setValue('subscriptionKey', flags.subscriptionKey, userConfig)
3534
}
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, Config} from '../../../utils/configfilehandler'
8+
9+
export default class ConfigShowLuis extends Command {
10+
static description = 'Display LUIS settings'
11+
12+
static flags: any = {
13+
help: flags.help({char: 'h', description: 'config:show:luis help'})
14+
}
15+
16+
async run() {
17+
const userConfig: Config = await getConfigFile(this.config.configDir)
18+
let luis: any = {}
19+
Object.keys(userConfig).forEach((key: string) => {
20+
if (key.startsWith('luis__')) {
21+
luis[key] = userConfig[key]
22+
}
23+
})
24+
this.log(JSON.stringify(luis, null, 2))
25+
}
26+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {expect, test} from '@oclif/test'
2+
import ConfigSetLuis from '../../../../src/commands/config/set/luis'
3+
const sinon = require('sinon')
4+
5+
describe('config:set:luis', () => {
6+
7+
beforeEach(() => {
8+
sinon.stub(ConfigSetLuis.prototype, 'promptSaveConfig').returns(true)
9+
})
10+
11+
afterEach(() => {
12+
sinon.restore();
13+
});
14+
15+
test
16+
.stdout()
17+
.command(['config:set:luis', '--help'])
18+
.it('should print the help contents when --help is passed as an argument', ctx => {
19+
expect(ctx.stdout).to.contain('Stores default LUIS application values in global config.')
20+
})
21+
22+
test
23+
.stdout()
24+
.stderr()
25+
.command(['config:set:luis'])
26+
.it('displays an message indication nothing saved if no config values passed', ctx => {
27+
expect(ctx.stdout).to.contain('No config settings specified')
28+
})
29+
30+
test
31+
.stdout()
32+
.stderr()
33+
.command(['config:set:luis', '--appId', '9999'])
34+
.it('displays an message indication values saved successfully', ctx => {
35+
expect(ctx.stdout).to.contain('Config settings saved')
36+
})
37+
38+
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {expect, test} from '@oclif/test'
2+
import {initTestConfigFile, deleteTestConfigFile, getConfigFile} from './../../../configfilehelper'
3+
4+
describe('config:show:luis', () => {
5+
before(async function() {
6+
await initTestConfigFile()
7+
});
8+
9+
after(async function() {
10+
await deleteTestConfigFile()
11+
});
12+
13+
test
14+
.stdout()
15+
.command(['config:show:luis'])
16+
.it('Displays config file luis data', ctx => {
17+
expect(ctx.stdout).to.contain('"luis__appId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"')
18+
})
19+
})

packages/config/test/configfilehelper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export async function initTestConfigFile() {
2727
qnamaker__subscriptionKey: "222222cccccctttttth223kk3k33",
2828
qnamaker__hostname: "https://somehost.net",
2929
qnamaker__endpointKey: "xxxxxxxxxxxxxxxxxxx",
30-
qnamaker__kbId: "xxxxxxxxxxxxxxxxxxxxxxx"
30+
qnamaker__kbId: "xxxxxxxxxxxxxxxxxxxxxxx",
31+
luis__appId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
3132
}
3233

3334
await fs.mkdirp(pathToConfigJson)

packages/lu/src/commands/luis/index.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/luis/src/commands/luis/application/create.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ export default class LuisApplicationCreate extends Command {
2424
description: flags.string({description: 'Description of LUIS application'}),
2525
versionId: flags.string({description: 'LUIS version Id. (mandatory, defaults to config:LUIS:versionId)'}),
2626
tokenizerVersion: flags.string({description: 'Version specifies how sentences are tokenized (optional). See also: https://aka.ms/luistokens'}),
27-
save: flags.string({description: 'Save configuration settings from imported app (appId & endpoint)'}),
27+
save: flags.boolean({description: 'Save configuration settings from imported app (appId & endpoint)'}),
2828
}
2929

3030
async run() {
3131
const {flags} = this.parse(LuisApplicationCreate)
3232
const flagLabels = Object.keys(LuisApplicationCreate.flags)
3333
const configDir = this.config.configDir
3434

35-
const {
35+
let {
3636
endpoint,
3737
subscriptionKey,
3838
name,
@@ -45,6 +45,8 @@ export default class LuisApplicationCreate extends Command {
4545

4646
const usageScenario = 'Bot Framework'
4747

48+
if (!culture) culture = 'en-us'
49+
4850
const requiredProps = {endpoint, subscriptionKey, name}
4951
utils.validateRequiredProps(requiredProps)
5052

@@ -59,7 +61,8 @@ export default class LuisApplicationCreate extends Command {
5961
if (save) {
6062
const config = {
6163
appId: newAppId,
62-
endpoint
64+
endpoint,
65+
subscriptionKey
6366
}
6467
const response = await this.saveImportedConfig(config, configDir)
6568
if (response) this.log('Config settings saved')

packages/luis/src/commands/luis/application/delete.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import {CLIError, Command, flags} from '@microsoft/bf-cli-command'
77

8+
const {cli} = require('cli-ux')
89
const utils = require('../../../utils/index')
910

1011
export default class LuisApplicationDelete extends Command {
@@ -37,6 +38,13 @@ export default class LuisApplicationDelete extends Command {
3738

3839
const client = utils.getLUISClient(subscriptionKey, endpoint)
3940

41+
if(!flags.appId) {
42+
const deleteAppConfirmation = await cli.confirm(`Are you sure you would like to delete app with id: ${appId}? (Y/N)`)
43+
if (!deleteAppConfirmation) {
44+
return this.log('No action taken')
45+
}
46+
}
47+
4048
try {
4149
const result = await client.apps.deleteMethod(appId)
4250
if (result.code === 'Success') {

packages/luis/src/commands/luis/application/import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class LuisApplicationImport extends Command {
3131

3232
let {endpoint, subscriptionKey, name, inVal} = await utils.processInputs(flags, flagLabels, configDir)
3333

34-
const requiredProps = {endpoint, subscriptionKey, name}
34+
const requiredProps = {endpoint, subscriptionKey}
3535
utils.validateRequiredProps(requiredProps)
3636

3737
inVal = inVal ? inVal.trim() : flags.in

0 commit comments

Comments
 (0)