Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2- Added v and version argument features #4

Merged
merged 5 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})
})
}
})
}
})
}
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# 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.
- NOTE: Because of the reason above the file ConsoleApplicationOSD600 has code no longer needed. Since we are still at the beginning of the class and it is hard to remove files form a commit I had to leave it THE WORKING CODE IS IN THE FOLDER: CommandToolLinkCheck
- Can run with the v or version argument to get the current version of the command line tool