Skip to content

Commit

Permalink
Make CLI catch exception when the user gives the dates out of order
Browse files Browse the repository at this point in the history
  • Loading branch information
borfast committed Jan 29, 2017
1 parent 7220a19 commit b5443bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016 Raúl Pedro Fernandes Santos
Copyright (c) 2017 Raúl Pedro Fernandes Santos

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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arrispwgen",
"version": "2.1.8",
"version": "2.1.9",
"description": "Arris Password of the Day Generator",
"main": "arrispwgen.js",
"engines": {
Expand Down
18 changes: 12 additions & 6 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ if (dates.length == 1) {
} else {
let start_date = moment(dates[0], input_date_format);
let end_date = moment(dates[1], input_date_format);
let potd = arrispwgen.generate_multi(start_date.toDate(), end_date.toDate(), seed);
try {
let potd = arrispwgen.generate_multi(start_date.toDate(), end_date.toDate(), seed);

for (let p in potd) {
data.push({
date: moment(parseInt(p)).format(long_date_format),
password: potd[p]
});
for (let p in potd) {
data.push({
date: moment(parseInt(p)).format(long_date_format),
password: potd[p]
});
}
} catch (e) {
// TODO: Be more specific in the exception that we're catching.
console.log(chalk.red('The given dates are out of order.'));
print_usage();
}
}

Expand Down

0 comments on commit b5443bc

Please sign in to comment.