Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* Licensed under the MIT License.
*/

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

export default class LuisInit extends Command {
export default class ConfigSetLuis extends Command {
static description = 'Stores default LUIS application values in global config.'

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

async run() {
const {flags} = this.parse(LuisInit)
const {flags} = this.parse(ConfigSetLuis)
const configDir = this.config.configDir

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

async promptSaveConfig(flags: any, configPath: string) {
const configPrefix = 'luis__'
let userConfig = await utils.getUserConfig(configPath)
if (userConfig === null) {
await utils.createConfigFile(configPath)
userConfig = {}
}
let userConfig: Config = await getConfigFile(configPath)
const saveConfigOptIn = await cli.confirm('Would you like to save the provided values to your global config file? (Y/N)')
if (saveConfigOptIn) {
// save config
const flagLabels = Object.keys(flags)
flagLabels.map(label => {
userConfig[`${configPrefix}${label}`] = flags[label]
})
await utils.writeUserConfig(userConfig, configPath)
await writeConfigFile(configPath, userConfig)
return true
}
return false
Expand Down
1 change: 0 additions & 1 deletion packages/config/src/commands/config/set/qnamaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export default class ConfigSetQnamaker extends Command {
async run() {
const {flags} = this.parse(ConfigSetQnamaker)
let userConfig: Config = await getConfigFile(this.config.configDir)

if (flags.subscriptionKey) {
this.setValue('subscriptionKey', flags.subscriptionKey, userConfig)
}
Expand Down
26 changes: 26 additions & 0 deletions packages/config/src/commands/config/show/luis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import {Command, flags} from '@microsoft/bf-cli-command'
import {getConfigFile, Config} from '../../../utils/configfilehandler'

export default class ConfigShowLuis extends Command {
static description = 'Display LUIS settings'

static flags: any = {
help: flags.help({char: 'h', description: 'config:show:luis help'})
}

async run() {
const userConfig: Config = await getConfigFile(this.config.configDir)
let luis: any = {}
Object.keys(userConfig).forEach((key: string) => {
if (key.startsWith('luis__')) {
luis[key] = userConfig[key]
}
})
this.log(JSON.stringify(luis, null, 2))
}
}
38 changes: 38 additions & 0 deletions packages/config/test/commands/config/set/luis.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {expect, test} from '@oclif/test'
import ConfigSetLuis from '../../../../src/commands/config/set/luis'
const sinon = require('sinon')

describe('config:set:luis', () => {

beforeEach(() => {
sinon.stub(ConfigSetLuis.prototype, 'promptSaveConfig').returns(true)
})

afterEach(() => {
sinon.restore();
});

test
.stdout()
.command(['config:set:luis', '--help'])
.it('should print the help contents when --help is passed as an argument', ctx => {
expect(ctx.stdout).to.contain('Stores default LUIS application values in global config.')
})

test
.stdout()
.stderr()
.command(['config:set:luis'])
.it('displays an message indication nothing saved if no config values passed', ctx => {
expect(ctx.stdout).to.contain('No config settings specified')
})

test
.stdout()
.stderr()
.command(['config:set:luis', '--appId', '9999'])
.it('displays an message indication values saved successfully', ctx => {
expect(ctx.stdout).to.contain('Config settings saved')
})

})
19 changes: 19 additions & 0 deletions packages/config/test/commands/config/show/luis.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {expect, test} from '@oclif/test'
import {initTestConfigFile, deleteTestConfigFile, getConfigFile} from './../../../configfilehelper'

describe('config:show:luis', () => {
before(async function() {
await initTestConfigFile()
});

after(async function() {
await deleteTestConfigFile()
});

test
.stdout()
.command(['config:show:luis'])
.it('Displays config file luis data', ctx => {
expect(ctx.stdout).to.contain('"luis__appId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"')
})
})
3 changes: 2 additions & 1 deletion packages/config/test/configfilehelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export async function initTestConfigFile() {
qnamaker__subscriptionKey: "222222cccccctttttth223kk3k33",
qnamaker__hostname: "https://somehost.net",
qnamaker__endpointKey: "xxxxxxxxxxxxxxxxxxx",
qnamaker__kbId: "xxxxxxxxxxxxxxxxxxxxxxx"
qnamaker__kbId: "xxxxxxxxxxxxxxxxxxxxxxx",
luis__appId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

await fs.mkdirp(pathToConfigJson)
Expand Down
18 changes: 0 additions & 18 deletions packages/lu/src/commands/luis/index.ts

This file was deleted.

9 changes: 6 additions & 3 deletions packages/luis/src/commands/luis/application/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export default class LuisApplicationCreate extends Command {
description: flags.string({description: 'Description of LUIS application'}),
versionId: flags.string({description: 'LUIS version Id. (mandatory, defaults to config:LUIS:versionId)'}),
tokenizerVersion: flags.string({description: 'Version specifies how sentences are tokenized (optional). See also: https://aka.ms/luistokens'}),
save: flags.string({description: 'Save configuration settings from imported app (appId & endpoint)'}),
save: flags.boolean({description: 'Save configuration settings from imported app (appId & endpoint)'}),
}

async run() {
const {flags} = this.parse(LuisApplicationCreate)
const flagLabels = Object.keys(LuisApplicationCreate.flags)
const configDir = this.config.configDir

const {
let {
endpoint,
subscriptionKey,
name,
Expand All @@ -45,6 +45,8 @@ export default class LuisApplicationCreate extends Command {

const usageScenario = 'Bot Framework'

if (!culture) culture = 'en-us'

const requiredProps = {endpoint, subscriptionKey, name}
utils.validateRequiredProps(requiredProps)

Expand All @@ -59,7 +61,8 @@ export default class LuisApplicationCreate extends Command {
if (save) {
const config = {
appId: newAppId,
endpoint
endpoint,
subscriptionKey
}
const response = await this.saveImportedConfig(config, configDir)
if (response) this.log('Config settings saved')
Expand Down
8 changes: 8 additions & 0 deletions packages/luis/src/commands/luis/application/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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

const {cli} = require('cli-ux')
const utils = require('../../../utils/index')

export default class LuisApplicationDelete extends Command {
Expand Down Expand Up @@ -37,6 +38,13 @@ export default class LuisApplicationDelete extends Command {

const client = utils.getLUISClient(subscriptionKey, endpoint)

if(!flags.appId) {
const deleteAppConfirmation = await cli.confirm(`Are you sure you would like to delete app with id: ${appId}? (Y/N)`)
if (!deleteAppConfirmation) {
return this.log('No action taken')
}
}

try {
const result = await client.apps.deleteMethod(appId)
if (result.code === 'Success') {
Expand Down
2 changes: 1 addition & 1 deletion packages/luis/src/commands/luis/application/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class LuisApplicationImport extends Command {

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

const requiredProps = {endpoint, subscriptionKey, name}
const requiredProps = {endpoint, subscriptionKey}
utils.validateRequiredProps(requiredProps)

inVal = inVal ? inVal.trim() : flags.in
Expand Down
4 changes: 2 additions & 2 deletions packages/luis/src/commands/luis/application/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export default class LuisApplicationQuery extends Command {
appId: flags.string({description: 'LUIS application Id (mandatory, defaults to config:LUIS:appId)'}),
query: flags.string({description: 'Query string to predict (mandatory)'}),
staging: flags.boolean({description: 'Presence of flag targets the staging app, if no flag passed defaults to production'}),
verbose: flags.string({description: 'Returns all intents, otherwise only top scoring intent. (default: false)'}),
verbose: flags.boolean({description: 'Returns all intents, otherwise only top scoring intent. (default: false)'}),
timezoneOffset: flags.string({description: 'Timezone offset for the location of the request in minutes (optional)'}),
log: flags.string({description: 'Logs query operation on service (default: true)'}),
log: flags.boolean({description: 'Logs query operation on service (default: true)'}),
}

async run() {
Expand Down
6 changes: 3 additions & 3 deletions packages/luis/src/commands/luis/application/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default class LuisApplicationRename extends Command {
endpoint: flags.string({description: 'LUIS endpoint hostname'}),
subscriptionKey: flags.string({description: 'LUIS cognitive services subscription key (mandatory, default: config:LUIS:subscriptionKey)'}),
appId: flags.string({description: 'LUIS application Id (mandatory, defaults to config:LUIS:appId)'}),
name: flags.string({description: 'Name of LUIS application (mandatory)'}),
description: flags.string({description: 'Description of LUIS application (mandatory)'}),
name: flags.string({description: 'Name of LUIS application (mandatory)', required: true}),
description: flags.string({description: 'Description of LUIS application'}),
}

async run() {
Expand All @@ -36,7 +36,7 @@ export default class LuisApplicationRename extends Command {
description
} = await utils.processInputs(flags, flagLabels, configDir)

const requiredProps = {endpoint, subscriptionKey, appId, name}
const requiredProps = {endpoint, subscriptionKey, appId}
utils.validateRequiredProps(requiredProps)

const client = utils.getLUISClient(subscriptionKey, endpoint)
Expand Down
4 changes: 2 additions & 2 deletions packages/luis/src/commands/luis/version/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export default class LuisVersionImport extends Command {
static flags: any = {
help: flags.help({char: 'h'}),
appId: flags.string({description: 'LUIS application Id (mandatory, defaults to config:LUIS:appId)'}),
versionId: flags.string({description: 'Version to export (mandatory, defaults to config:LUIS:versionId)'}),
versionId: flags.string({description: 'Version to export (defaults to config:LUIS:versionId)'}),
endpoint: flags.string({description: 'LUIS endpoint hostname'}),
subscriptionKey: flags.string({description: 'LUIS cognitive services subscription key (mandatory, default: config:LUIS:subscriptionKey)'}),
in: flags.string({char: 'i', description: 'File path containing LUIS application contents, uses STDOUT if not specified (mandatory)'})
in: flags.string({char: 'i', description: 'File path containing LUIS application contents, uses STDIN if not specified (mandatory)'})
}

async run() {
Expand Down
2 changes: 1 addition & 1 deletion packages/luis/src/commands/luis/version/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class LuisVersionRename extends Command {
subscriptionKey: flags.string({description: 'LUIS cognitive services subscription key (mandatory, default: config:LUIS:subscriptionKey)'}),
appId: flags.string({description: 'LUIS application Id (mandatory, defaults to config:LUIS:appId)'}),
versionId: flags.string({description: 'Version to update (mandatory, defaults to config:LUIS:versionId)'}),
newVersionId: flags.string({description: 'New version name (mandatory)'}),
newVersionId: flags.string({description: 'New version id (mandatory)'}),
}

async run() {
Expand Down
2 changes: 1 addition & 1 deletion packages/luis/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ module.exports.processInputs = processInputs
module.exports.validateRequiredProps = validateRequiredProps
module.exports.writeToConsole = writeToConsole
module.exports.writeToFile = writeToFile
module.exports.writeUserConfig = writeUserConfig
module.exports.writeUserConfig = writeUserConfig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('luis:application:create', () => {
.reply(201, '99999')
)
.stdout()
.command(['luis:application:create', '--save', 'true', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--name', 'orange_app', '--subscriptionKey', uuidv1(), '--culture', 'en-us', '--description', 'test description', '--versionId', '0.04'])
.command(['luis:application:create', '--save', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--name', 'orange_app', '--subscriptionKey', uuidv1(), '--culture', 'en-us', '--description', 'test description', '--versionId', '0.04'])
.it('creates a luis app and returns the new app\'s id', ctx => {
expect(ctx.stdout).to.contain('App successfully created with id 99999')
expect(ctx.stdout).to.contain('Config settings saved')
Expand Down
9 changes: 0 additions & 9 deletions packages/luis/test/commands/luis/application/import.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {expect, test} from '@oclif/test'
import * as cp from 'child_process';
const sinon = require('sinon')
const uuidv1 = require('uuid/v1')
const utils = require('../../../../src/utils/index')
Expand All @@ -22,14 +21,6 @@ describe('luis:application:import', () => {
expect(ctx.stdout).to.contain('Imports LUIS application from JSON or LU content.')
})

test
.stdout()
.stderr()
.command(['luis:application:import', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()])
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'name' missing.`)
})

test
.stdout()
.stderr()
Expand Down
3 changes: 2 additions & 1 deletion packages/luis/test/commands/luis/application/rename.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ describe('luis:application:rename', () => {
.stderr()
.command(['luis:application:rename', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--appId', uuidv1(), '--subscriptionKey', uuidv1(), '--description', 'test description'])
.it('displays an error if any required input parameters are missing', ctx => {
expect(ctx.stderr).to.contain(`Required input property 'name' missing.`)
expect(ctx.stderr).to.contain('Missing required flag:')
expect(ctx.stderr).to.contain('--name NAME')
})

test
Expand Down
2 changes: 0 additions & 2 deletions packages/luis/test/commands/luis/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {expect, test} from '@oclif/test'
import LuisInit from '../../../src/commands/luis/init'
const sinon = require('sinon')

describe('luis:index', () => {

Expand Down
38 changes: 0 additions & 38 deletions packages/luis/test/commands/luis/init.test.ts

This file was deleted.