-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding luis:application:list cmd #371
Merged
Merged
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b0573b2
Adding luis:application:list cmd
ec0266f
Merge branch 'master' into 308-luis-application-list
munozemilio 7b26854
Merge branch 'master' into 308-luis-application-list
munozemilio 23ab262
Merge branch 'master' into 308-luis-application-list
86898d2
Updating description
ec62c0e
Merge branch 'master' into 308-luis-application-list
cb87626
Merge branch 'master' into 308-luis-application-list
6bb94fb
Update desc
84bd6f5
Increase timeout
a9ef05e
Merge branch 'master' into 308-luis-application-list
3101f42
Update test
c074df3
Merge branch '308-luis-application-list' of https://github.com/micros…
77f3d96
Merge branch 'master' into 308-luis-application-list
c50639e
Add flags type
0af64b5
Merge branch '308-luis-application-list' of https://github.com/micros…
0af7757
Merge branch 'master' into 308-luis-application-list
munozemilio 1cc8a49
Merge branch 'master' into 308-luis-application-list
d6fb230
Merge branch 'master' into 308-luis-application-list
munozemilio 39ae6b4
Merge branch 'master' into 308-luis-application-list
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import {CLIError, Command, flags} from '@microsoft/bf-cli-command' | ||
|
||
const utils = require('../../../utils/index') | ||
|
||
export default class LuisApplicationList extends Command { | ||
static description = 'Lists all of the user applications' | ||
|
||
static examples = [` | ||
$ bf luis:application:list --endpoint {ENDPOINT} --subscriptionKey {SUBSCRIPTION_KEY} --take 3 | ||
$ bf luis:application:list --endpoint {ENDPOINT} --subscriptionKey {SUBSCRIPTION_KEY} --out {PATH_TO_JSON_FILE} | ||
`] | ||
|
||
static flags = { | ||
help: flags.help({char: 'h'}), | ||
endpoint: flags.string({description: 'LUIS endpoint hostname'}), | ||
subscriptionKey: flags.string({description: 'LUIS cognitive services subscription key (aka Ocp-Apim-Subscription-Key)'}), | ||
out: flags.string({char: 'o', description: 'Path to the directory where the exported file will be placed.'}), | ||
force: flags.boolean({char: 'f', description: 'If --out flag is provided with the path to an existing file, overwrites that file', default: false}), | ||
skip: flags.string({description: 'The number of entries to skip. The default is 0 (no skips)'}), | ||
take: flags.string({description: 'The number of etnries to return. The maximum page size is 500. The default is 100.'}), | ||
} | ||
|
||
async run() { | ||
const {flags} = this.parse(LuisApplicationList) | ||
const flagLabels = Object.keys(LuisApplicationList.flags) | ||
const configDir = this.config.configDir | ||
const options: any = {} | ||
|
||
let {endpoint, subscriptionKey, force, out, skip, take} = await utils.processInputs(flags, flagLabels, configDir) | ||
|
||
const requiredProps = {endpoint, subscriptionKey} | ||
utils.validateRequiredProps(requiredProps) | ||
|
||
const client = utils.getLUISClient(subscriptionKey, endpoint) | ||
|
||
if (skip) options.skip = parseInt(skip, 10) | ||
if (take) options.take = parseInt(take, 10) | ||
|
||
try { | ||
const appList = await client.apps.list(options, undefined) | ||
if (out) { | ||
const writtenFilePath: string = await utils.writeToFile(out, appList, force) | ||
this.log(`\nList successfully written to file: ${writtenFilePath}`) | ||
} else { | ||
await utils.writeToConsole(appList) | ||
this.log('\nList successfully output to console') | ||
} | ||
} catch (err) { | ||
throw new CLIError(`Failed to export application list: ${err}`) | ||
} | ||
} | ||
|
||
} |
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,78 @@ | ||
import {expect, test} from '@oclif/test' | ||
const sinon = require('sinon') | ||
const uuidv1 = require('uuid/v1') | ||
const utils = require('../../../../src/utils/index') | ||
const fs = require('fs-extra') | ||
import * as rimraf from 'rimraf' | ||
|
||
describe('luis:application:list', () => { | ||
|
||
before(() => { | ||
fs.mkdirSync('./testout'); | ||
}); | ||
|
||
after(() => { | ||
rimraf('./testout', (err) => { | ||
if (err) console.log(err); | ||
}) | ||
}); | ||
|
||
beforeEach(() => { | ||
sinon.stub(utils, 'processInputs').returnsArg(0) | ||
}) | ||
|
||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
test | ||
.stdout() | ||
.command(['luis:application:list', '--help']) | ||
.it('should print the help contents when --help is passed as an argument', ctx => { | ||
expect(ctx.stdout).to.contain('Lists all of the user applications') | ||
}) | ||
|
||
test | ||
.stdout() | ||
.stderr() | ||
.command(['luis:application:list', '--endpoint', 'https://westus.api.cognitive.microsoft.com']) | ||
.it('displays an error if any required input parameters are missing', ctx => { | ||
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`) | ||
}) | ||
|
||
test | ||
.nock('https://westus.api.cognitive.microsoft.com', api => api | ||
.get(uri => uri.includes('apps')) | ||
.reply(200, {name: 'testapp'}) | ||
) | ||
.stdout() | ||
.command(['luis:application:list', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com']) | ||
.it('displays a list of applications', ctx => { | ||
expect(ctx.stdout).to.contain('List successfully output to console') | ||
}) | ||
|
||
test | ||
.nock('https://westus.api.cognitive.microsoft.com', api => api | ||
.get(uri => uri.includes('apps')) | ||
.reply(200, {name: 'testapp'}) | ||
) | ||
.stdout() | ||
.command(['luis:application:list', '--out', './testout/test.json', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com']) | ||
.it('export a list of applications to the specified file', ctx => { | ||
expect(ctx.stdout).to.contain('List successfully written to file') | ||
expect(ctx.stdout).to.contain('test.json') | ||
}) | ||
|
||
test | ||
.nock('https://westus.api.cognitive.microsoft.com', api => api | ||
.get(uri => uri.includes('apps')) | ||
.reply(200, {name: 'testapp'}) | ||
) | ||
.stdout() | ||
.stderr() | ||
.command(['luis:application:list', '--out', 'xyz', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com']) | ||
.it('displays a list of applications and a success message in the console (since the target path provided is invalid)', ctx => { | ||
expect(ctx.stderr).to.contain('Target directory path doesn\'t exist:') | ||
}) | ||
|
||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spec states: Output results to specified file in JSON format, otherwise prints to STDOUT (optional)
Which suggests a file name can also be set as output, in the other hand, for this command I don't think there is a lot of value printing this to a file. @scheyal please comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest we just move fwd since it's already coded...discuss removing --out (if desired) later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we set the description as the spec please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not matching yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry...check again now