Skip to content

Commit

Permalink
Implement assignment downloading (see #1), code refactoring, update L…
Browse files Browse the repository at this point in the history
…ICENSE, update dependencies, step to v0.0.3
  • Loading branch information
szekelymilan committed Mar 20, 2020
1 parent b42631f commit 6f98709
Show file tree
Hide file tree
Showing 10 changed files with 1,314 additions and 886 deletions.
10 changes: 10 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "http://json.schemastore.org/prettierrc",
"printWidth": 100,
"singleQuote": true,
"useTabs": false,
"tabWidth": 2,
"semi": true,
"bracketSpacing": true,
"trailingComma": "all"
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Milan Szekely
Copyright (c) 2020 Milan Szekely

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@

Check your electronic diary in a second, by running a single command.

Too lazy for typing the flags? Run the CLI in **interactive mode**! 😎
Too lazy for typing? Run the CLI in **interactive mode**! 😎

## Features

- ⚡ Interactive mode via `--interactive`
- 💾 Saves login credentials
- 🖥 Shows subject averages
- 🏠 Downloads assignments
- ✅ Tested
- ⛏ Maintained

Expand All @@ -52,12 +53,13 @@ $ kreta --help
Check your electronic diary - from right inside your terminal.
Usage
$ kreta <options>
$ kreta <assignments|averages|reconfigure> [options]
Use 'kreta' for interactive mode.
Options
-a, --averages Show subject averages
-i, --interactive Interactive mode
--reconfigure Update configuration
assignments:
-o, --output Output folder (defaults to assignments)
Examples
See: https://github.com/szekelymilan/e-kreta-cli#examples
Expand All @@ -68,13 +70,19 @@ Examples
#### Reconfigure

```
$ kreta --reconfigure
$ kreta reconfigure
```

#### Show averages

```
$ kreta -a
$ kreta averages
```

#### Download assignments to My Assignments folder

```
$ kreta assignments -o "My Assignments"
```

## Contributors
Expand Down
125 changes: 57 additions & 68 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,88 @@ const inquirer = require('inquirer');
const meow = require('meow');
const updateNotifier = require('update-notifier');

const pkg = require('./package.json');
const _averages = require('./src/averages');
const _reconfigure = require('./src/reconfigure');
const utils = require('./src/utils');
const assignments = require('./src/assignments');
const averages = require('./src/averages');
const reconfigure = require('./src/reconfigure');

const cli = meow(`
const cli = meow(
`
${bold('Usage')}
$ kreta <options>
$ kreta <assignments|averages|reconfigure> [options]
Use 'kreta' for interactive mode.
${bold('Options')}
-a, --averages Show subject averages
-i, --interactive Interactive mode
--reconfigure Update configuration
assignments:
-o, --output Output folder (defaults to assignments)
${bold('Examples')}
See: https://github.com/szekelymilan/e-kreta-cli#examples
`,
{
flags: {
averages: {
type: 'boolean',
alias: 'a',
default: false
},
interactive: {
type: 'boolean',
alias: 'i',
default: false
{
flags: {
output: {
type: 'string',
alias: 'o',
},
},
reconfigure: {
type: 'boolean',
default: false
},
config: {
type: 'string',
default: undefined
}
}
});
},
);

const {
averages: AVERAGES,
interactive: INTERACTIVE,
reconfigure: RECONFIGURE,
config: CONFIG
} = cli.flags;
const { output: OUTPUT } = cli.flags;

async function doTask(task) {
switch (task) {
case 'assignments':
let output =
OUTPUT ||
(await inquirer.prompt([
{
type: 'input',
name: 'output',
message: 'Output folder:',
default: 'assignments',
},
]))['output'];

await assignments(output);
break;
case 'averages':
await averages();
break;
case 'reconfigure':
await reconfigure();
break;
default:
await interactive();
break;
}
}

async function _interactive() {
const answers = await inquirer.prompt([
async function interactive() {
const prompt = await inquirer.prompt([
{
type: 'checkbox',
name: 'tasks',
message: 'Select tasks:',
choices: [
{ name: 'Download assignments', value: 'assignments', checked: false },
{ name: 'Show subject averages', value: 'averages', checked: false },
{ name: 'Update configuration', value: 'reconfigure', checked: false },
{ name: 'Show averages', value: 'averages', checked: false }
]
}
],
},
]);

for (const task of answers['tasks']) {
switch (task) {
case 'averages':
await _averages();
break;
case 'reconfigure':
await _reconfigure();
break;
}
}
for (const task of prompt['tasks']) await doTask(task);
}

(async () => {
let noFlag = true;

updateNotifier({pkg}).notify();

if (INTERACTIVE) {
await _interactive();
return;
}

if (RECONFIGURE) {
await _reconfigure();
noFlag = false;
}

if (AVERAGES) {
await _averages();
noFlag = false;
}
updateNotifier({ pkg: utils.pkg }).notify();

if (noFlag)
await _interactive();
await doTask(cli.input[0]);

process.exit();
})();
Loading

0 comments on commit 6f98709

Please sign in to comment.