Skip to content

Commit

Permalink
✨ --from option added
Browse files Browse the repository at this point in the history
Closes #8
  • Loading branch information
vicalca committed Oct 21, 2019
1 parent f2309d6 commit b572f83
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,19 @@ if (cli.flags.log) {
fs.ensureFileSync(HISTORY_PATH);
try {
const res = JSON.parse(fs.readFileSync(HISTORY_PATH, 'utf8'));
console.log(JSON.stringify(res, null, 2));
// Get first day of the month
const today = new Date();
let date = new Date(today.getFullYear(), today.getMonth(), 1);
if (cli.flags.from) {
date = Date.parse(cli.flags.from);
if (isNaN(date)) {
throw Error("Invalid date format provided!");
}
}

for (let i = 0; i < res.length; i++) {
printLog(res[i], date);
}
}
catch (error) {
console.error(error);
Expand All @@ -70,6 +82,15 @@ if (cli.flags.log) {
process.exit(0);
}

function printLog(log, date) {
if(Date.parse(log.date) > date )
{
console.log(log.date);
console.log(JSON.stringify(log.messages, null, 2));
console.log();
}
}

function processAnswers(answers) {
let res =
`${template.yesterday()}
Expand Down

0 comments on commit b572f83

Please sign in to comment.