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

Commit 94a5217

Browse files
authored
Fixing try catch in generate/cs (#1114)
1 parent d80ed6a commit 94a5217

File tree

1 file changed

+35
-35
lines changed
  • packages/luis/src/commands/luis/generate

1 file changed

+35
-35
lines changed

packages/luis/src/commands/luis/generate/cs.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,49 +42,49 @@ export default class LuisGenerateCs extends Command {
4242
}
4343

4444
async run() {
45-
const {flags} = this.parse(LuisGenerateCs)
46-
let space = 'Luis'
47-
let stdInput = await this.readStdin()
45+
try {
46+
const {flags} = this.parse(LuisGenerateCs)
47+
let space = 'Luis'
48+
let stdInput = await this.readStdin()
4849

49-
if (!flags.in && !stdInput) {
50-
throw new CLIError('Missing input. Please use stdin or pass a file location with --in flag')
51-
}
50+
if (!flags.in && !stdInput) {
51+
throw new CLIError('Missing input. Please use stdin or pass a file location with --in flag')
52+
}
5253

53-
const pathPrefix = flags.in && path.isAbsolute(flags.in) ? '' : process.cwd()
54-
let app: any
55-
try {
56-
app = flags.in ? await fs.readJSON(path.join(pathPrefix, flags.in)) : JSON.parse(stdInput as string)
57-
} catch (err) {
58-
throw new CLIError(err)
59-
}
54+
const pathPrefix = flags.in && path.isAbsolute(flags.in) ? '' : process.cwd()
55+
let app: any
56+
try {
57+
app = flags.in ? await fs.readJSON(path.join(pathPrefix, flags.in)) : JSON.parse(stdInput as string)
58+
} catch (err) {
59+
throw new CLIError(err)
60+
}
6061

61-
flags.className = flags.className || app.name
62+
flags.className = flags.className || app.name
6263

63-
const dot_index = flags.className ? flags.className.lastIndexOf('.') : -1
64-
if (dot_index !== -1) {
65-
space = flags.className.substr(0, dot_index)
66-
flags.className = flags.className.substr(dot_index + 1)
67-
} else {
68-
flags.className = upperFirst(camelCase(flags.className))
69-
}
64+
const dot_index = flags.className ? flags.className.lastIndexOf('.') : -1
65+
if (dot_index !== -1) {
66+
space = flags.className.substr(0, dot_index)
67+
flags.className = flags.className.substr(dot_index + 1)
68+
} else {
69+
flags.className = upperFirst(camelCase(flags.className))
70+
}
7071

71-
if ('regexEntities' in app) {
72-
app = this.renameProp('regexEntities', 'regex_entities', app)
73-
}
72+
if ('regexEntities' in app) {
73+
app = this.renameProp('regexEntities', 'regex_entities', app)
74+
}
7475

75-
this.reorderEntities(app, 'entities')
76-
this.reorderEntities(app, 'prebuiltEntities')
77-
this.reorderEntities(app, 'closedLists')
78-
this.reorderEntities(app, 'regex_entities')
79-
this.reorderEntities(app, 'patternAnyEntities')
80-
this.reorderEntities(app, 'composites')
76+
this.reorderEntities(app, 'entities')
77+
this.reorderEntities(app, 'prebuiltEntities')
78+
this.reorderEntities(app, 'closedLists')
79+
this.reorderEntities(app, 'regex_entities')
80+
this.reorderEntities(app, 'patternAnyEntities')
81+
this.reorderEntities(app, 'composites')
8182

82-
const outputPath = flags.out ? file.validatePath(flags.out, flags.className + '.cs', flags.force) : flags.out
83+
const outputPath = flags.out ? file.validatePath(flags.out, flags.className + '.cs', flags.force) : flags.out
8384

84-
this.log(
85-
`Generating file at ${outputPath || 'stdout'} that contains class ${space}.${flags.className}.`
86-
)
87-
try {
85+
this.log(
86+
`Generating file at ${outputPath || 'stdout'} that contains class ${space}.${flags.className}.`
87+
)
8888
await LuisToCsConverter.writeFromLuisJson(app, flags.className, space, outputPath)
8989
} catch (err) {
9090
if (err instanceof exception) {

0 commit comments

Comments
 (0)