-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·110 lines (95 loc) · 3.45 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env node
/*
* kollavarsham
* http://kollavarsham.org
*
* Copyright (c) 2014-2016 The Kollavarsham Team
* Licensed under the MIT license.
*/
'use strict';
var chalk = require('chalk');
var nopt = require('nopt');
var pkg = require('./package.json');
var cliHelper = require('./cli-helper');
var Kollavarsham = require('kollavarsham');
var updateNotifier = require('update-notifier');
//TODO akutty
//Option for setting latitude/longitude using preset values from ./locations.js
var opts = nopt({
'help' : Boolean,
'version' : Boolean,
'system' : ['InPancasiddhantika', 'SuryaSiddhanta'],
'mode' : Number,
'showlongitudes' : Boolean,
'showlatitudes' : Boolean,
'latitude' : Number,
'longitude' : Number
}, {
h : '--help',
v : '--version',
s : '--system',
m : '--mode',
a : '--showlatitudes',
o : '--showlongitudes',
t : '--latitude',
g : '--longitude',
});
var args = opts.argv.remain;
var firstArgument = args[0];
var notifier = updateNotifier({
packageName : pkg.name,
packageVersion : pkg.version
});
if (notifier.update) {
notifier.notify();
}
cliHelper.openingMessage(pkg.version);
//TODO: This is the temporary output function
var printOutput = function (kollavarshamDate) {
var pad = function (num, size) {
var s = '000000000' + num;
return s.substr(s.length - size);
};
if (kollavarshamDate.globals) {
var result = 'Saka : ' + pad(kollavarshamDate.globals.YearSaka, 4) + '\t' + pad(kollavarshamDate.globals.tithiDay, 2) + ' ' +
kollavarshamDate.globals.masa + ' (' + pad(kollavarshamDate.globals.masaNum, 2) + ') ' + '\t[' + kollavarshamDate.globals.paksa + ']\n';
result += 'Saura: ' + pad(kollavarshamDate.globals.YearSaka, 4) + '\t' + pad(kollavarshamDate.day, 2) + ' ' +
kollavarshamDate.globals.sauraMasa + ' (' + pad(kollavarshamDate.month, 2) + ') ' + '\t' + kollavarshamDate.globals.naksatra + '\n';
result += 'ME : ' + pad(kollavarshamDate.year, 4) + '\t' + pad(kollavarshamDate.day, 2) + ' ' +
kollavarshamDate.globals.malayalaMasa + ' (' + pad(kollavarshamDate.globals.malayalaMasaNum, 2) + ') ' + '\t' + kollavarshamDate.globals.malayalaNaksatra + '\n';
return result;
}
return kollavarshamDate.toString();
};
if (opts.help) {
return cliHelper.helpMessage();
} else if (opts.version) {
return console.log('Installed version of %s is %s\n', pkg.name, chalk.green.bold(pkg.version));
} else if (opts.showlatitudes) {
return cliHelper.showLatitudes();
} else if (opts.showlongitudes) {
return cliHelper.showLongitudes();
}
else {
var settings = cliHelper.parseOptions(opts);
console.log(settings);
var kollavarsham = new Kollavarsham(settings);
if (firstArgument) {
var mode = opts.mode || 0;
if (mode === 0) {
console.log('You are trying to convert the Gregorian date ' + chalk.blue.bold('%s') +
' to Kollavarsham date', firstArgument);
var date = cliHelper.parseDate(firstArgument);
if (date) {
cliHelper.displaySettings(kollavarsham.getSettings());
var kollavarshamDate = kollavarsham.fromGregorianDate(date);
console.log(chalk.cyan('\nOutput\n------'));
console.log(chalk.white(printOutput(kollavarshamDate)));
//console.log('\n' + JSON.stringify(kollavarshamDate, null, 4));
}
} else {
console.log('You are trying to convert the Kollavarsham date ' + chalk.blue.bold('%s') +
' to Gregorian date', firstArgument);
}
}
}