33 * Licensed under the MIT License.
44 */
55
6- import { CLIError , Command , flags } from '@microsoft/bf-cli-command'
7- import { throws } from 'assert'
6+ import { Command , flags } from '@microsoft/bf-cli-command'
87const { cli} = require ( 'cli-ux' )
9- const utils = require ( '../../utils/index' )
8+ import { getConfigFile , writeConfigFile , Config } from '../../../ utils/configfilehandler'
109
11- export default class LuisInit extends Command {
10+ export default class ConfigSetLuis extends Command {
1211 static description = 'Stores default LUIS application values in global config.'
1312
1413 static examples = [ `
@@ -24,7 +23,7 @@ export default class LuisInit extends Command {
2423 }
2524
2625 async run ( ) {
27- const { flags} = this . parse ( LuisInit )
26+ const { flags} = this . parse ( ConfigSetLuis )
2827 const configDir = this . config . configDir
2928
3029 if ( Object . entries ( flags ) . length === 0 && flags . constructor === Object ) {
@@ -37,24 +36,20 @@ export default class LuisInit extends Command {
3736 return this . log ( 'Unable to save config settings' )
3837 } catch ( err ) {
3938 this . log ( `Unable to save config settings: ${ err } ` )
39+ this . _help ( )
4040 }
4141 }
4242
4343 async promptSaveConfig ( flags : any , configPath : string ) {
4444 const configPrefix = 'luis__'
45- let userConfig = await utils . getUserConfig ( configPath )
46- if ( userConfig === null ) {
47- await utils . createConfigFile ( configPath )
48- userConfig = { }
49- }
45+ let userConfig : Config = await getConfigFile ( configPath )
5046 const saveConfigOptIn = await cli . confirm ( 'Would you like to save the provided values to your global config file? (Y/N)' )
5147 if ( saveConfigOptIn ) {
52- // save config
5348 const flagLabels = Object . keys ( flags )
5449 flagLabels . map ( label => {
5550 userConfig [ `${ configPrefix } ${ label } ` ] = flags [ label ]
5651 } )
57- await utils . writeUserConfig ( userConfig , configPath )
52+ await writeConfigFile ( configPath , userConfig )
5853 return true
5954 }
6055 return false
0 commit comments