-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (67 loc) · 1.99 KB
/
index.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
#!/usr/bin/env node
'use strict';
var program = require('commander');
var wfhlib = require('./wfhlib.js');
var site = 'https://www.wfh.io';
program
.version('0.0.3');
program
.command('categories')
.description('Display job categories')
.action(function() {
wfhlib.makeRequest(site, '/api/categories.json', wfhlib.showCategories);
});
program
.command('company [id]')
.description('Display company with id')
.action(function(id) {
wfhlib.makeRequest(site, '/api/companies/' + id + '.json', wfhlib.showCompany);
});
program
.command('companies')
.description('Display companies')
.option('-p, --page [id]', 'Specify page to request')
.action(function(options) {
var page = options.page || 1;
wfhlib.makeRequest(site, '/api/companies.json?page=' + page, wfhlib.showCompanies);
});
program
.command('job [id]')
.description('Display job with id')
.action(function(id) {
wfhlib.makeRequest(site, '/api/jobs/' + id + '.json', wfhlib.showJob);
});
program
.command('jobs')
.description('Display jobs')
.option('-c, --category [id]', 'Limit results by category')
.option('-p, --page [id]', 'Specify page to request')
.option('-s, --source [id]', 'Limit results to source')
.action(function(options) {
var category = options.category || undefined;
var page = options.page || 1;
var source = options.source || undefined;
var uri = '/api/jobs.json?page=' + page;
if (category !== undefined) {
uri = uri + '&category_id=' + category;
}
if (source !== undefined) {
uri = uri + '&source_id=' + source;
}
wfhlib.makeRequest(site, uri, wfhlib.showJobs);
});
program
.command('sources')
.description('Display job sources')
.action(function() {
wfhlib.makeRequest(site, '/api/sources.json', wfhlib.showSources);
});
program
.command('*', '', {noHelp: true})
.action(function(env) {
program.outputHelp();
});
if (!process.argv.slice(2).length) {
program.outputHelp();
}
program.parse(process.argv);