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

Commit 8d90555

Browse files
author
JSpru
authored
Adding luis:application:show cmd (#379)
* Adding luis:application:show cmd * Add flags type
1 parent 9458ab6 commit 8d90555

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*!
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import {CLIError, Command, flags} from '@microsoft/bf-cli-command'
7+
8+
const utils = require('../../../utils/index')
9+
10+
export default class LuisApplicationShow extends Command {
11+
static description = 'Shows application information'
12+
13+
static examples = [`
14+
$ bf luis:application:show --appId {APPLICATION_ID} --endpoint {ENDPOINT} --subscriptionKey {SUBSCRIPTION_KEY}
15+
`]
16+
17+
static flags: any = {
18+
help: flags.help({char: 'h'}),
19+
endpoint: flags.string({description: 'LUIS endpoint hostname'}),
20+
subscriptionKey: flags.string({description: 'LUIS cognitive services subscription key (mandatory, default: config:LUIS:subscriptionKey)'}),
21+
appId: flags.string({description: 'LUIS application Id (mandatory, defaults to config:LUIS:appId)'}),
22+
}
23+
24+
async run() {
25+
const {flags} = this.parse(LuisApplicationShow)
26+
const flagLabels = Object.keys(LuisApplicationShow.flags)
27+
const configDir = this.config.configDir
28+
29+
let {endpoint, subscriptionKey, appId} = await utils.processInputs(flags, flagLabels, configDir)
30+
31+
const requiredProps = {endpoint, subscriptionKey, appId}
32+
utils.validateRequiredProps(requiredProps)
33+
34+
const client = utils.getLUISClient(subscriptionKey, endpoint)
35+
36+
try {
37+
const appData = await client.apps.get(appId)
38+
if (appData) {
39+
await utils.writeToConsole(appData)
40+
this.log('\nApplication data successfully output to console')
41+
}
42+
} catch (err) {
43+
throw new CLIError(`Failed to retrieve application data: ${err}`)
44+
}
45+
}
46+
47+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {expect, test} from '@oclif/test'
2+
const sinon = require('sinon')
3+
const uuidv1 = require('uuid/v1')
4+
const utils = require('../../../../src/utils/index')
5+
const fs = require('fs-extra')
6+
import * as rimraf from 'rimraf'
7+
8+
describe('luis:application:show', () => {
9+
10+
beforeEach(() => {
11+
sinon.stub(utils, 'processInputs').returnsArg(0)
12+
})
13+
14+
afterEach(() => {
15+
sinon.restore();
16+
});
17+
18+
test
19+
.stdout()
20+
.command(['luis:application:show', '--help'])
21+
.it('should print the help contents when --help is passed as an argument', ctx => {
22+
expect(ctx.stdout).to.contain('Shows application information')
23+
})
24+
25+
test
26+
.stdout()
27+
.stderr()
28+
.command(['luis:application:show', '--endpoint', 'https://westus.api.cognitive.microsoft.com'])
29+
.it('displays an error if any required input parameters are missing', ctx => {
30+
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`)
31+
})
32+
33+
test
34+
.nock('https://westus.api.cognitive.microsoft.com', api => api
35+
.get(uri => uri.includes('apps'))
36+
.reply(200, {id: '99999', name: 'test-app'})
37+
)
38+
.stdout()
39+
.command(['luis:application:show', '--appId', uuidv1(), '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com'])
40+
.it('displays a list of application versions', ctx => {
41+
expect(ctx.stdout).to.contain('Application data successfully output to console')
42+
expect(ctx.stdout).to.contain('99999')
43+
expect(ctx.stdout).to.contain('test-app')
44+
})
45+
46+
})

0 commit comments

Comments
 (0)