Skip to content

Commit

Permalink
Removed global vars, refactoring #1
Browse files Browse the repository at this point in the history
Edited variable names, refactoring #2

Added custom func to ease up code space, refactoring #3
  • Loading branch information
Niaz-Ul-Haque committed Oct 28, 2020
1 parent 5711f64 commit 9fd631d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 36 deletions.
84 changes: 49 additions & 35 deletions src/cli.js
Expand Up @@ -7,40 +7,25 @@ const readline = require("readline");

require("dotenv").config();

let flag = 0;

export function cli(args) {
let stat = "--all";
let flag = 0;

if (args[3] == "--ignore" && args[4]){
flag = 1
if (args[3] == "--ignore" && args[4]) {
flag = 1;
}

if (args[2] == "--help" || args[2] == "--h" || args[2] == "-h") {
console.log("Help Options");
console.log("'--v, --version, -v' : Will show the version of the cli");
console.log("'--h, --help, -h' : Will open up list of params you can use");
console.log(
"'--f, --files, -f' : Will show the type of files the program can format"
);
console.log("'--all' : Will ouptut all the links");
console.log("'--good' : Will ouptut only the working links");
console.log("'--bad' : Will ouptut only the bad links");
getHelp();
exit();
} else if (args[2] == undefined) {
console.log("Steps on how this cli works");
console.log("You should run like this 'nlinks <filename>'");
console.log("Run the '--help' options for more helpful information");
getWhenEmptyArgs();
exit();
} else if (args[2] == "--version" || args[2] == "--v" || args[2] == "-v") {
console.log("CLI Name: nlinks");
console.log("Version: ^0.1");
console.log("Made by: Mohammed Niaz Ul Haque");
console.log("Github: https://github.com/Niaz-Ul-Haque/nlinks");
getVersion();
exit();
} else if (args[2] == "--files" || args[2] == "--f" || args[2] == "-f") {
console.log("All the files are supported except for direct links.");
console.log("Will be adding the functon on release 0.2 or 0.3");
getFilesSupportedInfo();
exit();
} else if (args[3] == "--all" || args[3] == "--good" || args[3] == "--bad") {
stat = args[3];
Expand All @@ -60,39 +45,39 @@ export function cli(args) {
}

for await (const line of rl) {
let flag2 = 1
let flag2 = 1;
const link_reg = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi;

let myArray = line.match(link_reg);
if (myArray == null) continue;
let lineFromFile = line.match(link_reg);
if (lineFromFile == null) continue;

if( flag == 1 && flag2 == 1){
if (flag == 1 && flag2 == 1) {
const ignoreULRfile = fs.createReadStream(args[4]);
const lineOfUrls = readline.createInterface({
input: ignoreULRfile,
crlfDelay: Infinity,
});
for await (let l of lineOfUrls) {
let ignoreURL = l.match(link_reg);
if (ignoreURL != null){
if (ignoreURL.toString() === myArray.toString()){
console.log("SKIP / IGNORE")
flag2 = 1
if (ignoreURL != null) {
if (ignoreURL.toString() === lineFromFile.toString()) {
console.log("SKIP / IGNORE");
flag2 = 1;
break;
} else{
} else {
flag2 = 0;
}
}
}
}
}

if(flag == 1 && flag2 == 1) continue;
if (flag == 1 && flag2 == 1) continue;

myArray = line.match(link_reg)[0];
lineFromFile = line.match(link_reg)[0];

async function simple() {
const results = await link.check({
path: myArray,
path: lineFromFile,
});
switch (results.links[0].status) {
case 200:
Expand Down Expand Up @@ -139,3 +124,32 @@ export function cli(args) {
}
processLineByLine();
}

function getHelp() {
console.log("Help Options");
console.log("'--v, --version, -v' : Will show the version of the cli");
console.log("'--h, --help, -h' : Will open up list of params you can use");
console.log(
"'--f, --files, -f' : Will show the type of files the program can format"
);
console.log("'--all' : Will ouptut all the links");
console.log("'--good' : Will ouptut only the working links");
console.log("'--bad' : Will ouptut only the bad links");
}

function getWhenEmptyArgs() {
console.log("Steps on how this cli works");
console.log("You should run like this 'nlinks <filename>'");
console.log("Run the '--help' options for more helpful information");
}

function getVersion() {
console.log("CLI Name: nlinks");
console.log("Version: ^0.1");
console.log("Made by: Mohammed Niaz Ul Haque");
console.log("Github: https://github.com/Niaz-Ul-Haque/nlinks");
}
function getFilesSupportedInfo() {
console.log("All the files are supported except for direct links.");
console.log("Will be adding the functon on release 0.2 or 0.3");
}
3 changes: 2 additions & 1 deletion urls.html
Expand Up @@ -3,7 +3,8 @@
#Feed excluded due to getaddrinfo ENOTFOUND s-aleinikov.blog.ca s-aleinikov.blog.ca:80
#[http://s-aleinikov.blog.ca/feed/atom/posts/]
#name=Sergey Aleinikov

https://learn.senecacollege.ca/
https://senecacollege.ca

#Feed excluded due to getaddrinfo ENOTFOUND ejtorre.blog.ca ejtorre.blog.ca:80
#[http://ejtorre.blog.ca/feed/rss2/posts/]
Expand Down

0 comments on commit 9fd631d

Please sign in to comment.