-
Notifications
You must be signed in to change notification settings - Fork 59
/
index.js
59 lines (47 loc) · 1.21 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
'use strict';
process.on('uncaughtException', (err) => {
console.error(err);
});
var Imooc = require('./imooc');
var program = require('commander');
var logger = require('./lib/logger');
var display = require('./lib/display');
var config = require('./conf/config.default');
let imooc = new Imooc(config);
program
.version('1.1.0')
.option('-s, --search <n>', 'Search course specified by keywords', search)
.option('-l, --list <n>', 'Show the Chapters and Lessons by course Id', list)
.option('-d, --download <n>', 'Download the Course By course Id', download)
.parse(process.argv);
if (!program.search &&
!program.list &&
!program.download) {
imooc.loopCourse(fail);
}
function search(keyword) {
imooc.getCourses(keyword, function(err, courses) {
if (err) {
logger.error(err);
} else {
display.viewCourses(courses);
}
})
}
function list(courseName) {
imooc.getLessons(courseName, function(err, lessons) {
if (err) {
logger.error(err);
} else {
display.viewLessons(lessons);
}
})
}
function download(ids) {
ids = ids.split(',');
imooc.setTarget(ids);
imooc.loopCourse(fail);
}
function fail(err) {
if (err) logger.error(err);
}