forked from Laboratoria/bog001-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
53 lines (46 loc) · 1.29 KB
/
cli.js
File metadata and controls
53 lines (46 loc) · 1.29 KB
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
#!/usr/bin/env node
const mdLinks = require('./index.js');
const validateLink = require('./validate.js');
const estadisticas = require('./stats.js');
const process = require('process');
let options = process.argv
let archivoPath = process.argv[2];
let validateBroken = true;
let validate = false;
let stats = false
//itero en options y las dos opciones les devulvo un valor boolean
options.forEach(e => {
if (e == "--validate")
validate = true
if (e == "--stats")
stats = true
});
//condicional para mi cli
if(!validate && !stats){
mdLinks(archivoPath).then(console.log)
}
else if(validate && !stats){
mdLinks(archivoPath,{validate: true}).then((result) =>{
return validateLink(result);
})
.then((result) => {
console.log(result)
})
}
else if(!validate && stats){
mdLinks(archivoPath, {validate: false})
.then((result) => {
console.log(estadisticas(result))
})
}
else if(validate && stats){
mdLinks(archivoPath,{validate: true}).then((result) =>{
return validateLink(result);
})
.then((result) => {
console.log(result)
estadisticas(result,validateBroken);
})
}
else{
console.log('no usaste options, puedes usar estos comandos --validate --stats o las dos juntas');}