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

Commit 132e0cd

Browse files
author
Shuai Wang
authored
Support passing in information about external functions in lg:analyze (#1237)
* support of adding external functions as arguments * remove only * fix test cases failed * revert comment
1 parent eac7a60 commit 132e0cd

File tree

9 files changed

+60
-37
lines changed

9 files changed

+60
-37
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 13 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ OPTIONS
437437
-i, --in=in (required) LG File or folder that contains .lg file(s)
438438
-o, --out=out Output file or folder name. If not specified stdout will be used as output
439439
-r, --recurse Consider sub-folders to find .lg file(s)
440+
-e, --external-functions Pass a list of external functions and add them to Expression functions, seprated by ",". for example, "function1,function2,function3"
440441
```
441442

442443
_See code: [@microsoft/bf-lg-cli](https://github.com/microsoft/botframework-cli/tree/master/packages/lg/src/commands/lg/analyze.ts)_

packages/lg/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ OPTIONS
4747
-i, --in=in (required) LG File or folder that contains .lg file(s)
4848
-o, --out=out Output file or folder name. If not specified stdout will be used as output
4949
-r, --recurse Consider sub-folders to find .lg file(s)
50+
-e, --external-functions Pass a list of external functions and add them to Expression functions, seprated by ",". for example, "function1,function2,function3"
5051
```
5152

5253
_See code: [src/commands/lg/analyze.ts](https://github.com/microsoft/botframework-cli/tree/master/packages/lg/src/commands/lg/analyze.ts)_

packages/lg/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@oclif/command": "^1.5.19",
1212
"@oclif/config": "^1.14.0",
1313
"botbuilder-lg":"4.13.0",
14+
"adaptive-expressions":"4.13.0",
1415
"delay": "^4.3.0",
1516
"fs-extra": "^8.1.0",
1617
"lodash": "^4.17.15",

packages/lg/src/commands/lg/analyze.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {Command, flags, CLIError} from '@microsoft/bf-cli-command'
1010
import {Helper} from '../../utils'
1111
import {Templates, DiagnosticSeverity, Diagnostic} from 'botbuilder-lg'
12+
import {Expression, ExpressionEvaluator} from 'adaptive-expressions'
1213
import * as path from 'path'
1314
import * as fs from 'fs-extra'
1415

@@ -28,6 +29,7 @@ export default class AnalyzeCommand extends Command {
2829
recurse: flags.boolean({char: 'r', description: 'Consider sub-folders to find .lg file(s)'}),
2930
out: flags.string({char: 'o', description: 'Output file or folder name. If not specified stdout will be used as output'}),
3031
force: flags.boolean({char: 'f', description: 'If --out flag is provided with the path to an existing file, overwrites that file'}),
32+
'external-functions': flags.string({char: 'e', helpValue: 'function1,function2', description: 'Pass a list of external functions and add them to Expression functions, seprated by ",". for example, "function1,function2,function3"'}),
3133
help: flags.help({char: 'h', description: 'lg:analyze help'}),
3234
}
3335

@@ -37,6 +39,13 @@ export default class AnalyzeCommand extends Command {
3739
const lgFilePaths = Helper.findLGFiles(flags.in, flags.recurse)
3840

3941
Helper.checkInputAndOutput(lgFilePaths)
42+
if (flags['external-functions']) {
43+
const functionList = flags['external-functions'].split(',')
44+
for (const func of functionList)
45+
Expression.functions.add(func, new ExpressionEvaluator(func, () => {
46+
return {value: undefined, error: ''}
47+
}))
48+
}
4049

4150
const allTemplates = []
4251
for (const filePath of lgFilePaths) {

packages/lg/test/commands/lg/analyze.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ describe('lg:analyze lg file', async () => {
3838
await TestUtil.compareFiles(path.join(generatedFolderPath, 'analysisResult.txt'), path.join(verifiedFolderPath, 'analysisResult1.txt'))
3939
})
4040

41+
test
42+
.command(['lg:analyze',
43+
'--in',
44+
path.join(__dirname, testcaseFolderPath, 'analyze/external.lg'),
45+
'--out',
46+
generatedFolder,
47+
'-r',
48+
'-f',
49+
'--external-functions',
50+
'ReadDatabase'])
51+
.it('', async () => {
52+
await TestUtil.compareFiles(path.join(generatedFolderPath, 'analysisResult.txt'), path.join(verifiedFolderPath, 'analysisResult3.txt'))
53+
})
54+
4155
// lg files folder
4256
test
4357
.command(['lg:analyze',
@@ -46,7 +60,9 @@ describe('lg:analyze lg file', async () => {
4660
'--out',
4761
generatedFolder,
4862
'-r',
49-
'-f'])
63+
'-f',
64+
'--external-functions',
65+
'ReadDatabase'])
5066
.it('', async () => {
5167
await TestUtil.compareFiles(path.join(generatedFolderPath, 'analysisResult.txt'), path.join(verifiedFolderPath, 'analysisResult2.txt'))
5268
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#CallMyName(name)
2+
- hello ${name} ${GetToDos()}
3+
4+
#GetToDos
5+
- Here is your Todos: ${ReadDatabase()} ${LogWaiting()}
6+
7+
#LogWaiting
8+
- Is there any thing I can help you with?

packages/lg/test/fixtures/verified/analysisResult2.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
external.lg:CallMyName references:
2+
external.lg:GetToDos references:
3+
external.lg: CallMyName
4+
external.lg:LogWaiting references:
5+
external.lg: CallMyName, GetToDos
16
generator.lg:greeting references:
27
generator.lg:welcome references:
38
generator.lg: greeting
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
external.lg:CallMyName references:
2+
external.lg:GetToDos references:
3+
external.lg: CallMyName
4+
external.lg:LogWaiting references:
5+
external.lg: CallMyName, GetToDos

0 commit comments

Comments
 (0)