That feeling when you finally make the -f flag ake a file output AND add support for setting the name for that file.
This commit is contained in:
+2
-1
@@ -7,4 +7,5 @@ config.txt
|
|||||||
test.txt
|
test.txt
|
||||||
rete-test.sh
|
rete-test.sh
|
||||||
rh.txt
|
rh.txt
|
||||||
.vscode/
|
.vscode/
|
||||||
|
passed.txt
|
||||||
+9
-2
@@ -2,15 +2,19 @@ require "option_parser"
|
|||||||
require "http/client"
|
require "http/client"
|
||||||
require "validator"
|
require "validator"
|
||||||
|
|
||||||
|
output = "passed.txt"
|
||||||
|
|
||||||
OptionParser.parse do |parser|
|
OptionParser.parse do |parser|
|
||||||
parser.banner = "Usage: rete [arguments] [urls]"
|
parser.banner = "Usage: rete [arguments] [urls]"
|
||||||
parser.on("-f FILE", "--file=FILE", "Checks all urls in a txt file.") { |file|
|
parser.on("-f FILE", "--file=FILE", "Checks all urls in a txt file.") { |file|
|
||||||
urls = File.read(file)
|
urls = File.read(file)
|
||||||
checkUrlFromFile urls
|
checkUrlFromFile urls, output
|
||||||
exit 0}
|
exit 0}
|
||||||
parser.on("-v", "--version", "Displays current version of rete.") {
|
parser.on("-v", "--version", "Displays current version of rete.") {
|
||||||
puts "Rete 1.0 by koffee.zip"
|
puts "Rete 1.0 by koffee.zip"
|
||||||
exit(0)}
|
exit(0)}
|
||||||
|
parser.on("-o FILENAME", "--output=FILENAME", "Sets teh name of the outputted file. -f flag required") {|filename|
|
||||||
|
output = filename}
|
||||||
parser.on("-h", "--help", "Show this help") do
|
parser.on("-h", "--help", "Show this help") do
|
||||||
puts parser
|
puts parser
|
||||||
exit
|
exit
|
||||||
@@ -22,7 +26,7 @@ OptionParser.parse do |parser|
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def checkUrlFromFile(content) # Sorry for the crappy method name.
|
def checkUrlFromFile(content, output) # Sorry for the crappy method name.
|
||||||
repeat = 0
|
repeat = 0
|
||||||
working = 0
|
working = 0
|
||||||
notWorking = 0
|
notWorking = 0
|
||||||
@@ -50,6 +54,9 @@ def checkUrlFromFile(content) # Sorry for the crappy method name.
|
|||||||
response = client.get("/")
|
response = client.get("/")
|
||||||
if config.includes?(response.status_code.to_s)
|
if config.includes?(response.status_code.to_s)
|
||||||
puts "#{urls[repeat]} is a valid URL and works. Status code: #{response.status_code}"
|
puts "#{urls[repeat]} is a valid URL and works. Status code: #{response.status_code}"
|
||||||
|
File.open("#{output}", "a") do |file|
|
||||||
|
file.puts urls[repeat]
|
||||||
|
end
|
||||||
working += 1
|
working += 1
|
||||||
else
|
else
|
||||||
puts "#{urls[repeat]} is a valid URL but does not work. Status Code: #{response.status_code}"
|
puts "#{urls[repeat]} is a valid URL but does not work. Status Code: #{response.status_code}"
|
||||||
|
|||||||
Reference in New Issue
Block a user