diff --git a/package-lock.json b/package-lock.json index 0bea9a1..1656293 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "e-kreta-cli", - "version": "0.0.6", + "version": "0.0.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ce03a4d..bc7a1e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "e-kreta-cli", - "version": "0.0.6", + "version": "0.0.7", "description": "Check your electronic diary - from right inside your terminal.", "main": "cli.js", "scripts": {}, diff --git a/src/reconfigure.js b/src/reconfigure.js index c83656b..3063167 100644 --- a/src/reconfigure.js +++ b/src/reconfigure.js @@ -7,49 +7,54 @@ const utils = require('./utils'); inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt')); module.exports = async () => { - const institutes = await utils.getInstitutes(); + try { + const institutes = await utils.getInstitutes(); - const fuse = new Fuse(institutes, { - shouldSort: true, - threshold: 0.6, - location: 0, - distance: 100, - maxPatternLength: 32, - minMatchCharLength: 1, - keys: ['Name', 'InstituteCode'], - }); + const fuse = new Fuse(institutes, { + shouldSort: true, + threshold: 0.6, + location: 0, + distance: 100, + maxPatternLength: 32, + minMatchCharLength: 1, + keys: ['Name', 'InstituteCode'], + }); - const answers = await inquirer.prompt([ - { - type: 'autocomplete', - name: 'institute', - message: 'Select an institute:', - source: function(answers, input = '') { - return new Promise(function(resolve) { - if (input.length < 1) return resolve(institutes.map(e => e.Name.trim())); + const answers = await inquirer.prompt([ + { + type: 'autocomplete', + name: 'institute', + message: 'Select an institute:', + source: function(answers, input = '') { + return new Promise(function(resolve) { + if (input.length < 1) return resolve(institutes.map(e => e['Name'].trim())); - resolve(fuse.search(input).map(e => e.Name.trim())); - }); + resolve(fuse.search(input).map(e => e.item['Name'].trim())); + }); + }, }, - }, - { - type: 'input', - name: 'username', - message: 'Username:', - }, - { - type: 'input', - name: 'password', - message: 'Password:', - }, - ]); + { + type: 'input', + name: 'username', + message: 'Username:', + }, + { + type: 'input', + name: 'password', + message: 'Password:', + }, + ]); - utils.conf.set( - 'institute', - institutes.filter(x => x.Name.trim() == answers['institute'])[0]['InstituteCode'], - ); - utils.conf.set('username', Base64.encode(answers['username'])); - utils.conf.set('password', Base64.encode(answers['password'])); + utils.conf.set( + 'institute', + institutes.filter(x => x.Name.trim() == answers['institute'])[0]['InstituteCode'], + ); + utils.conf.set('username', Base64.encode(answers['username'])); + utils.conf.set('password', Base64.encode(answers['password'])); - console.log(green('The configuration has been updated successfully.')); + console.log(green('The configuration has been updated successfully.')); + } catch (e) { + console.error(red('An error occured.')); + console.error(e); + } };