-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathindex.js
executable file
·111 lines (100 loc) · 2.84 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env node
'use strict';
var path = require('path');
var program = require('commander');
//var cliMd = require("mdy");
var list = require('./lib/list');
var reader = require('./lib/reader');
var open = require('open');
var pkg = require(path.join(__dirname, 'package.json'));
program
.version(pkg.version)
.description(pkg.description);
program
.command('top')
.description('List Medium Top Stories')
.option('-n, --number <int>', 'specify number of stories')
.option('-o, --open', 'Open the story in browser')
.option('-m, --markdown', 'View the story in Markdown format')
.action(function(options){
var count = options.number || 20;
list('top', {
count: count,
open: options.open,
markdown: options.markdown
});
});
program
.command('tag')
.arguments('<tag>')
.description('List trending Medium Stories by tag')
.option('-n, --number <int>', 'specify number of stories')
.option('-l, --latest', 'get latest instead of trending stories')
.option('-o, --open', 'Open the story in browser')
.option('-m, --markdown', 'View the story in Markdown format')
.action(function(tag, options){
var count = options.number || 10;
var latest = options.latest || false;
list('tag', {
value: tag,
count: count,
latest: latest,
open: options.open,
markdown: options.markdown
});
});
program
.command('author')
.arguments('<author>')
.description('List Medium Stories by author')
.option('-n, --number <int>', 'specify number of stories')
.option('-o, --open', 'Open the story in browser')
.option('-m, --markdown', 'View the story in Markdown format')
.action(function(author, options){
var count = options.number || 10;
list('author', {
value: author,
count: count,
open: options.open,
markdown: options.markdown
});
});
program
.command('search')
.alias('s')
.arguments('<searchTerms...>')
.description('Search for stories')
.option('-n, --number <int>', 'specify number of stories')
.option('-o, --open', 'Open the story in browser')
.option('-m, --markdown', 'View the story in Markdown format')
.action(function(searchTerms, options){
var count = options.number || 10;
list('search', {
value: searchTerms.join('%20'),
count: count,
open: options.open,
markdown: options.markdown
});
});
program
.command('read <url>')
.option('-m, --markdown', 'View the story in Markdown format')
.description('Read the story right in your terminal')
.action(function(url, options){
reader.show({
url: url,
markdown: options.markdown
});
});
program
.command('open <url>')
.description('Opens it in your default browser')
.option('-a, --app <application>', 'specify app to open the url. Eg: firefox')
.action(function(url, options){
open(url, options.app);
});
program.parse(process.argv);
if (!process.argv.slice(2).length) {
// Show help by default
program.outputHelp();
}