forked from Laboratoria/lim-2018-01-FE-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
41 lines (38 loc) · 1.46 KB
/
cli.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
#!/usr/bin/env node
const mdLinks = require('./index');
const program = require('commander');
const options = {
validate: false,
stats: false
};
program
.arguments('<path>')
.option('-v, --validate')
.option('-s, --stats')
.action(path => {
options.validate = program.validate;
options.stats = program.stats;
mdLinks(path, options)
.then(arrayLinks => {
if (options.validate && !options.stats) {
arrayLinks.forEach(link => {
console.log(`${link.href}\t ${link.text}\t ${link.file}\t ${link.status}\t${link.statusText}`);
})
} else if (!options.validate && options.stats) {
arrayLinks.forEach(link => {
console.log(`total:${link.total}\nunique:${link.unique}`);
})
} else if (options.validate && options.stats) {
arrayLinks.forEach(link => {
console.log(`total:${link.total}\nunique:${link.unique}\nbroken:${link.broken}`)
})
} else if (!options.validate && !options.stats) {
arrayLinks.forEach(link => {
console.log(`${link.href}\t ${link.text}\t ${link.file}\t`);
})
} else {
console.log(arrayLinks);
}
})
})
.parse(process.argv);