-
Notifications
You must be signed in to change notification settings - Fork 0
/
devto.js
64 lines (55 loc) · 1.95 KB
/
devto.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
const { Command } = require('commander');
const getArticles = require('./features/getArticles');
const getFollowers = require('./features/getFollowers');
const getReadingList = require('./features/getReadingList');
const postArticle = require('./features/postArticle');
const { resetAuthToken } = require('./utils/authTokenUtils');
const program = new Command();
const auth = program.command('auth');
auth
.command('remove')
.description('Remove an Auth Token.')
.action(resetAuthToken);
// Get followers feature
const followers = program.command('followers');
followers
.description('Get a list of your followers')
.option('-n, --num-users <num>', 'Number of users to display', 20)
.action(getFollowers);
// Article features
const articles = program
.command('articles')
.description('Get articles or Post an article.');
// Articles: create
articles
.command('create')
.description('Create a draft or publish an article from a markdown file')
.requiredOption('-f, --input-file <file>', 'The markdown file which is the post [required]')
.action(function post() {
postArticle(this.inputFile);
});
// Articles: get
articles
.command('get')
.description('Get all your articles.')
.option('-u, --unpublished', 'Fetch your unpublished articles.')
.option('-p, --published', 'Fetch your published articles.')
.option('-a, --all', 'Fetch all articles.', true)
.action(function get() {
const { unpublished, published } = this;
let scope = 'all';
if (unpublished && !published) scope = 'unpublished';
else if (published && !unpublished) scope = 'published';
getArticles(0, scope);
});
// TODO Articles: get homepage articles
// TODO Articles: update user article?
// Reading List commands
program
.command('rlist')
.description('Get your Reading List')
.option('-n --num-items <num>', 'How many to fetch at once', 30)
.action(function getList() {
getReadingList(1, this.numItems);
});
program.parse(process.argv);