@@ -46,10 +46,8 @@ export default class LuisBuild extends Command {
4646 async run ( ) {
4747 try {
4848 const { flags} = this . parse ( LuisBuild )
49- const userConfig = await utils . getUserConfig ( this . config . configDir )
50-
51- flags . stdin = await this . readStdin ( )
5249
50+ // Luconfig overrides flags
5351 let files : string [ ] = [ ]
5452 if ( flags . luConfig ) {
5553 const configFilePath = path . resolve ( flags . luConfig )
@@ -67,32 +65,36 @@ export default class LuisBuild extends Command {
6765 }
6866 }
6967
70- if ( ! flags . stdin && ! flags . in && files . length === 0 ) {
68+ // Flags override userConfig
69+ let { inVal, authoringKey, botName, region, out, defaultCulture, fallbackLocale, suffix, dialog, force, luConfig, deleteOldVersion, log}
70+ = await utils . processInputs ( flags , Object . keys ( LuisBuild . flags ) , this . config . configDir )
71+
72+ flags . stdin = await this . readStdin ( )
73+
74+ if ( ! flags . stdin && ! inVal && files . length === 0 ) {
7175 throw new CLIError ( 'Missing input. Please use stdin or pass a file or folder location with --in flag' )
7276 }
7377
74- if ( ! flags . authoringKey && ( ! userConfig || ! userConfig . authoringKey ) ) {
75- throw new CLIError ( 'Missing luis authoring key. Please pass authoring key with --authoringKey flag' )
76- } else {
77- flags . authoringKey = flags . authoringKey || userConfig . authoringKey
78+ if ( ! authoringKey ) {
79+ throw new CLIError ( 'Missing LUIS authoring key. Please pass authoring key with --authoringKey flag or specify via bf config:set:luis.' )
7880 }
7981
80- if ( ! flags . botName ) {
81- throw new CLIError ( 'Missing bot name. Please pass bot name with --botName flag' )
82+ if ( ! botName ) {
83+ throw new CLIError ( 'Missing bot name. Please pass bot name with --botName flag. ' )
8284 }
8385
84- if ( flags . dialog && flags . dialog !== recognizerType . MULTILANGUAGE && flags . dialog !== recognizerType . CROSSTRAINED ) {
85- throw new CLIError ( 'Recognizer type specified by --dialog is not right. Please specify [multiLanguage|crosstrained]' )
86+ if ( dialog && dialog !== recognizerType . MULTILANGUAGE && dialog !== recognizerType . CROSSTRAINED ) {
87+ throw new CLIError ( 'Recognizer type specified by --dialog is not right. Please specify [multiLanguage|crosstrained]. ' )
8688 }
8789
88- flags . defaultCulture = flags . defaultCulture && flags . defaultCulture !== '' ? flags . defaultCulture : 'en-us'
89- flags . region = flags . region && flags . region !== '' ? flags . region : 'westus'
90- flags . suffix = flags . suffix && flags . suffix !== '' ? flags . suffix : await username ( ) || 'development'
91- flags . fallbackLocale = flags . fallbackLocale && flags . fallbackLocale !== '' ? flags . fallbackLocale : 'en-us'
90+ defaultCulture = defaultCulture && defaultCulture !== '' ? defaultCulture : 'en-us'
91+ region = region && region !== '' ? region : 'westus'
92+ suffix = suffix && suffix !== '' ? suffix : await username ( ) || 'development'
93+ fallbackLocale = fallbackLocale && fallbackLocale !== '' ? fallbackLocale : 'en-us'
9294
9395 // create builder class
9496 const builder = new Builder ( ( input : string ) => {
95- if ( flags . log ) this . log ( input )
97+ if ( log ) this . log ( input )
9698 } )
9799
98100 let luContents : any [ ] = [ ]
@@ -102,19 +104,19 @@ export default class LuisBuild extends Command {
102104
103105 if ( flags . stdin && flags . stdin !== '' ) {
104106 // load lu content from stdin and create default recognizer, multiRecognier and settings
105- if ( flags . log ) this . log ( 'Load lu content from stdin\n' )
106- const content = new Content ( flags . stdin , new LUOptions ( 'stdin' , true , flags . defaultCulture , path . join ( process . cwd ( ) , 'stdin' ) ) )
107+ if ( log ) this . log ( 'Load lu content from stdin\n' )
108+ const content = new Content ( flags . stdin , new LUOptions ( 'stdin' , true , defaultCulture , path . join ( process . cwd ( ) , 'stdin' ) ) )
107109 luContents . push ( content )
108110 multiRecognizers . set ( 'stdin' , new MultiLanguageRecognizer ( path . join ( process . cwd ( ) , 'stdin.lu.dialog' ) , { } ) )
109- settings . set ( 'stdin' , new Settings ( path . join ( process . cwd ( ) , `luis.settings.${ flags . suffix } .${ flags . region } .json` ) , { } ) )
111+ settings . set ( 'stdin' , new Settings ( path . join ( process . cwd ( ) , `luis.settings.${ suffix } .${ region } .json` ) , { } ) )
110112 const recognizer = Recognizer . load ( content . path , content . name , path . join ( process . cwd ( ) , `${ content . name } .dialog` ) , settings . get ( 'stdin' ) , { } )
111113 recognizers . set ( content . name , recognizer )
112114 } else {
113- if ( flags . log ) this . log ( 'Loading files...\n' )
115+ if ( log ) this . log ( 'Loading files...\n' )
114116
115- // get lu files from flags. in.
116- if ( flags . in && flags . in !== '' ) {
117- const luFiles = await file . getLuFiles ( flags . in , true , fileExtEnum . LUFile )
117+ // get lu files from in.
118+ if ( inVal && inVal !== '' ) {
119+ const luFiles = await file . getLuFiles ( inVal , true , fileExtEnum . LUFile )
118120 files . push ( ...luFiles )
119121 }
120122
@@ -123,22 +125,22 @@ export default class LuisBuild extends Command {
123125
124126 // load lu contents from lu files
125127 // load existing recognizers, multiRecogniers and settings or create default ones
126- const loadedResources = await builder . loadContents ( files , flags . defaultCulture , flags . suffix , flags . region )
128+ const loadedResources = await builder . loadContents ( files , defaultCulture , suffix , region )
127129 luContents = loadedResources . luContents
128130 recognizers = loadedResources . recognizers
129131 multiRecognizers = loadedResources . multiRecognizers
130132 settings = loadedResources . settings
131133 }
132134
133135 // update or create and then train and publish luis applications based on loaded resources
134- if ( flags . log ) this . log ( 'Handling applications...' )
135- const dialogContents = await builder . build ( luContents , recognizers , flags . authoringKey , flags . region , flags . botName , flags . suffix , flags . fallbackLocale , flags . deleteOldVersion , multiRecognizers , settings )
136+ if ( log ) this . log ( 'Handling applications...' )
137+ const dialogContents = await builder . build ( luContents , recognizers , authoringKey , region , botName , flags . suffix , fallbackLocale , deleteOldVersion , multiRecognizers , settings )
136138
137139 // write dialog assets based on config
138- if ( flags . dialog ) {
139- const writeDone = await builder . writeDialogAssets ( dialogContents , flags . force , flags . out , flags . dialog , flags . luConfig )
140- const dialogFilePath = ( flags . stdin || ! flags . in ) ? process . cwd ( ) : flags . in . endsWith ( fileExtEnum . LUFile ) ? path . dirname ( path . resolve ( flags . in ) ) : path . resolve ( flags . in )
141- const outputFolder = flags . out ? path . resolve ( flags . out ) : dialogFilePath
140+ if ( dialog ) {
141+ const writeDone = await builder . writeDialogAssets ( dialogContents , force , out , dialog , luConfig )
142+ const dialogFilePath = ( flags . stdin || ! inVal ) ? process . cwd ( ) : inVal . endsWith ( fileExtEnum . LUFile ) ? path . dirname ( path . resolve ( inVal ) ) : path . resolve ( inVal )
143+ const outputFolder = out ? path . resolve ( out ) : dialogFilePath
142144 if ( writeDone ) {
143145 this . log ( `Successfully wrote .dialog files to ${ outputFolder } \n` )
144146 } else {
0 commit comments