diff --git a/.gitignore b/.gitignore index d35bbf7..d28da82 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ -.idea/ \ No newline at end of file +.idea/ +warning \ No newline at end of file diff --git a/README.md b/README.md index 36e463b..673e7ff 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Type: `Number` Set the year ## Release History -- 2014-09-21 v0.1.0 Initial release +- 2014-09-22 v0.1.0 Initial release [travis-url]: http://travis-ci.org/charliedowler/cal [travis-image]: https://secure.travis-ci.org/charliedowler/cal.png?branch=master \ No newline at end of file diff --git a/cli.js b/cli.js old mode 100644 new mode 100755 index 765b32f..0fab1fa --- a/cli.js +++ b/cli.js @@ -1,46 +1,59 @@ +#!/usr/bin/env node var argv = require('minimist')(process.argv.slice(2)); var Cal = require('./'); var table = require('text-table'); var _ = require('underscore'); var cal = new Cal(); +var fs = require('fs'); +var colors = require('colors'); -if (argv.m && typeof argv.m == 'number') { - cal.setMonth(argv.m); -} -else if (argv.y && typeof argv.y == 'number') { - cal.setYear(argv.y); -} +fs.exists('./warning', function(exists) { + if (!exists && !argv.i) { + console.log('======================================'.yellow); + console.log('| This overwrote the existing cal |'.yellow); + console.log('| command type npm uninstall -g |'.yellow); + console.log('| to undo this change. |'.yellow); + console.log('======================================'.yellow); + fs.writeFile('./warning'); + } + if (argv.m && typeof argv.m == 'number') { + cal.setMonth(argv.m); + } + else if (argv.y && typeof argv.y == 'number') { + cal.setYear(argv.y); + } -var days = cal.daysOfWeek.map(function(day) { - return day.substring(0, 2); -}); -var firstDay = cal.getFirstDayOfMonth().substring(0, 2); + var days = cal.daysOfWeek.map(function(day) { + return day.substring(0, 2); + }); + var firstDay = cal.getFirstDayOfMonth().substring(0, 2); -var header = table([[' ', cal.getMonth() + ' ' + cal.getYear(), ' ']], { align: [ 'c' ] }); -var c = function() { - var startDay = 0; - var arr = []; - for (var day = 1; day <= cal.getDaysThisMonth(); day++) { - arr.push(day); - } - _.filter(days, function(day, index) { - if (day == firstDay) { - startDay = index; + var header = table([[ ' ', cal.getMonth() + ' ' + cal.getYear(), ' ']], { align: [ 'c', 'c', 'c'] }); + var c = function() { + var startDay = 0; + var arr = []; + for (var day = 1; day <= cal.getDaysThisMonth(); day++) { + arr.push(day); } - }); - for(var i =0;i