-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (48 loc) · 1.63 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
const Reddit = require('./src/Reddit');
const program = require('commander');
const livestream = require('./src/livestream');
program
.version('1.0.0')
.description('Retrieves post titles from a subreddit or a reddit user. \n');
program
.option('-c, --count <count>', 'Specify the count of posts you want', '25');
program
.command('user <username>')
.alias('u')
.description('Get post titles from a user.')
.action((username) => {
if(Number(program.count) < 99) {
Reddit.getUser(username)
.getSubmissions({ limit: Number(program.count) })
.map(post => post.title)
.then(console.log)
.catch(console.error);
}
});
program
.command('subreddit <subredditname>')
.alias('s')
.description('Get post titles from a subreddit.')
.action((subredditname) => {
if(Number(program.count) < 99) {
Reddit.getSubreddit(subredditname)
.getHot({limit: Number(program.count)})
.map(post => post.title)
.then(console.log)
.catch(console.error);
}
});
program
.command('stream <subredditname>')
.alias('t')
.description('Streams the post titles from a specified subreddit')
.action((subredditname) => {
console.log('\x1b[34m', 'Ctrl-C to quit');
livestream(subredditname);
});
program.parse(process.argv);
if(program.count >= 99) {
console.error('I can\'t display more than 99 items in console');
}
if(process.argv.length === 2)
console.error('No arguments provided. \nUsage: index [options] [command]');