-
Notifications
You must be signed in to change notification settings - Fork 2
/
contests.js
44 lines (39 loc) · 1.86 KB
/
contests.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
#!/usr/bin/env node
import { Command } from "commander/esm.mjs";
const program = new Command();
import {websiteTypes,messageTypes} from "./utils/types.js"
import showMessage from "./lib/showMessage.js"
import fetchData from "./lib/fetchData.js"
import printTable from "./lib/printTable.js"
program
.version("1.0.0")
.description("This is a cli app to get details about upcoming programming contests")
program
.usage('[options1, options2...]', 'shows details about upcoming contests')
.option(`-cf, --codeforces`, "Upcoming contests on Codeforces",websiteTypes.CODEFORCES)
.option(`-cc, --codechef`, "Upcoming contests on Codechef",websiteTypes.CODECHEF)
.option(`-tc, --topcoder`, "Upcoming contests on Top Coder",websiteTypes.TOP_CODER)
.option(`-ac, --atcoder`, "Upcoming contests on At Coder",websiteTypes.AT_CODER)
.option(`-cs, --csacademy`, "Upcoming contests on CS Academy",websiteTypes.CS_ACADEMY)
.option(`-hr, --hackerrank`, "Upcoming contests on Hacker Rank",websiteTypes.HACKERRANK)
.option(`-he, --hackerearth`, "Upcoming contests on Hacker Earth",websiteTypes.HACKEREARTH)
.option(`-ks, --kickstart`, "Upcoming contests on Google Kickstart",websiteTypes.KICK_START)
.option(`-lc --leetcode`, "Upcoming contests on Leetcode",websiteTypes.LEETCODE)
.option(`-a --all`, "Upcoming contests on all platforms",websiteTypes.ALL)
program.parse(process.argv);
const options=program.opts();
const keys=Object.keys(options);
if(keys.length===0){
showMessage("Too few arguments provided",messageTypes.ERROR);
showMessage("Type <contests -h> to get list of all commands",messageTypes.SUCCESS);
}
else{
for(let key in options){
fetchData(options[key]).then(response=>{
printTable(response.data,options[key]);
// console.log(response.data);
}).catch(error=>{
showMessage(error,messageTypes.ERROR);
})
}
}