Skip to content

Commit

Permalink
Merge pull request #4 from joey2031/issue-2
Browse files Browse the repository at this point in the history
Issue 2- Added v and version argument features
  • Loading branch information
strawberries73 authored Oct 6, 2020
2 parents b0d95ae + c4b5613 commit 7fa896d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
56 changes: 33 additions & 23 deletions CommandToolLinkCheck/CommandTool/index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
const fs=require('fs')
const fetch=require('node-fetch')
const path=require('path')
const packageJson = require('./package.json');


console.log(process.argv)
const greetingMessage=()=>{
console.log("This is command line tool");
console.log("if red links are not working");
console.log("if green links are working")
console.log("Run with a file name to process the file, run with the argument v or version to get the version of this tool")
}


if(process.argv.length==2){
if(process.argv.length == 2){
greetingMessage();
console.log("Hello");
}
else{
const filePath=path.join(__dirname,process.argv[2])
fs.readFile(filePath,'utf-8',(err,data)=>{
if(err){
console.log("Fail to read file",err)
}
else{
const validUrl=data.match(/(http|https)(:\/\/)([\w+\-&@`~#$%^*.=/?:]+)/gi)
validUrl.forEach((url)=>{
fetch(url,{method:'HEAD',timeout:2000})
.then((res)=>{
if(res.status==200)
console.log(res.status,url)
else if(res.status==400||res.status==404)
console.log(res.status,url)
else console.log(res.status,url)
})
.catch((error)=>{
console.log("404",url)
else{ // more then 2

if (process.argv[2] == "v" || process.argv[2] == "version") {
console.log(packageJson.name + " Version " + packageJson.version);
} else{

const filePath=path.join(__dirname,process.argv[2])
fs.readFile(filePath,'utf-8',(err,data)=>{
if(err){
console.log("Fail to read file",err)
}
else{
const validUrl=data.match(/(http|https)(:\/\/)([\w+\-&@`~#$%^*.=/?:]+)/gi)
validUrl.forEach((url)=>{
fetch(url,{method:'HEAD',timeout:2000})
.then((res)=>{
if(res.status==200)
console.log(res.status,url)
else if(res.status==400||res.status==404)
console.log(res.status,url)
else console.log(res.status,url)
})
.catch((error)=>{
console.log("404",url)
})
})
})
}
})
}
})
}
}
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# OSD600-Journey-on-rocky-trails
As much as I desire to become more acquainted with C++, I was truly not happy with the slow progression and outcome of this version. What was I thinking?!
I have made a version 2 on node.js.

Clone CommandLinkToolCheck since this is the successful version.
Clone ConsoleApplicationOSD600 since this is the successful version.

Install project dependencies:

Expand All @@ -20,5 +19,4 @@ Features:
Prints good Urls in green and prints broken Urls in red.
https://github.com/strawberries73/OSD600-Journey-on-rocky-trails/blob/master/vscode.jpg



Note: CommandToolLinkCheck is no longer valid code for this project

0 comments on commit 7fa896d

Please sign in to comment.