-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
32 lines (25 loc) · 1.3 KB
/
app.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
#!/usr/bin/env node
"use strict";
var clim8Pkg = require("./package.json");
var clim8Program = require("commander");
var Weather = require("./lib/Weather");
var weather = new Weather();
var EXIT_ERROR = 1; // clim8 program
clim8Program.version(clim8Pkg.version).usage("[options] <option>").option("-C, --city [city]", "provide city").option("-S, --citystate [city,state]", "provide city and state", function (items) {
return items.split(",");
}).option("-L, --coordinates [latitude,longitude]", "provide latitude and longitude", function (items) {
return items.split(",");
}).parse(process.argv);
if (clim8Program.city) weather.getCurrentWeatherByCity(clim8Program.city);else if (clim8Program.citystate) {
if (clim8Program.citystate.length !== 2) {
console.log("City and state are mandatory, example: London,Uk");
process.exit(EXIT_ERROR);
}
weather.getCurrentWeatherByCityAndState(clim8Program.citystate[0], clim8Program.citystate[1]);
} else if (clim8Program.coordinates) {
if (clim8Program.coordinates.length !== 2) {
console.log("Latitude and Longitude are mandatory, example: 44.4949,11.3426");
process.exit(EXIT_ERROR);
}
weather.getCurrentWeatherByCoordinates(clim8Program.coordinates[0], clim8Program.coordinates[1]);
} else console.log("Confused? Do you need some help? clim8 --help");