This repository has been archived by the owner on Oct 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,13 @@ const meow = require('meow'); | |
const linky = require('@bokub/linky'); | ||
const chalk = require('chalk'); | ||
const display = require('./src/display'); | ||
const inquire = require('./src/inquire'); | ||
const save = require('./src/save'); | ||
const validate = require('./src/validate'); | ||
|
||
const cli = meow(` | ||
const c = meow(` | ||
Usage | ||
$ linky (hour|day|month|year) -u <email> -p <password> [options] | ||
$ linky [(hour|day|month|year)] [options] | ||
Options | ||
--user -u Linky client area e-mail | ||
|
@@ -20,9 +21,11 @@ const cli = meow(` | |
--end -e End of the custom time period (DD/MM/YYYY) | ||
Examples | ||
$ linky month -u [email protected] -p password123 | ||
$ linky | ||
$ linky year | ||
$ linky month -u [email protected] | ||
$ linky day -s 24/08/2018 -e 06/09/2018 | ||
$ linky hour -u [email protected] -p password123 -o ../export/hourly-data.json | ||
$ linky day -u [email protected] -p password123 -s 24/08/2018 -e 06/09/2018 | ||
`, { | ||
description: false, | ||
flags: { | ||
|
@@ -34,7 +37,28 @@ const cli = meow(` | |
} | ||
}); | ||
|
||
async function main(i) { | ||
main(c).catch(err => { | ||
console.error(chalk.red(err)); | ||
process.exit(1); | ||
}); | ||
|
||
async function main(cli) { | ||
await inquire(cli); | ||
|
||
const validationResult = validate(cli); | ||
if (validationResult.error) { | ||
console.error(chalk.red(validationResult.message)); | ||
cli.showHelp(); | ||
process.exit(1); | ||
} | ||
|
||
const data = await getData(cli); | ||
await save(data, cli.flags.output); | ||
|
||
display(data); | ||
} | ||
|
||
async function getData(i) { | ||
const session = await linky.login(i.flags.user, i.flags.password); | ||
let data; | ||
switch (i.input[0]) { | ||
|
@@ -55,17 +79,3 @@ async function main(i) { | |
} | ||
return data; | ||
} | ||
|
||
const validationResult = validate(cli); | ||
if (validationResult.error) { | ||
console.error(chalk.red(validationResult.message)); | ||
cli.showHelp(); | ||
} | ||
|
||
main(cli).then(data => { | ||
save(data, cli.flags.output); | ||
display(data); | ||
}).catch(err => { | ||
console.error(chalk.red(err)); | ||
process.exit(1); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.