Skip to content

Commit

Permalink
Fix bug in reconfigure (#7), upgrade to v0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
szekelymilan committed Apr 11, 2020
1 parent 3a22379 commit b876a1c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {},
Expand Down
83 changes: 44 additions & 39 deletions src/reconfigure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

0 comments on commit b876a1c

Please sign in to comment.