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:
2026-07-16 00:16:43 -06:00
parent e1753ab2ce
commit 2bd4cd4ed2
2 changed files with 11 additions and 3 deletions
+1
View File
@@ -8,3 +8,4 @@ test.txt
rete-test.sh
rh.txt
.vscode/
passed.txt
+9 -2
View File
@@ -2,15 +2,19 @@ require "option_parser"
require "http/client"
require "validator"
output = "passed.txt"
OptionParser.parse do |parser|
parser.banner = "Usage: rete [arguments] [urls]"
parser.on("-f FILE", "--file=FILE", "Checks all urls in a txt file.") { |file|
urls = File.read(file)
checkUrlFromFile urls
checkUrlFromFile urls, output
exit 0}
parser.on("-v", "--version", "Displays current version of rete.") {
puts "Rete 1.0 by koffee.zip"
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
puts parser
exit
@@ -22,7 +26,7 @@ OptionParser.parse do |parser|
end
end
def checkUrlFromFile(content) # Sorry for the crappy method name.
def checkUrlFromFile(content, output) # Sorry for the crappy method name.
repeat = 0
working = 0
notWorking = 0
@@ -50,6 +54,9 @@ def checkUrlFromFile(content) # Sorry for the crappy method name.
response = client.get("/")
if config.includes?(response.status_code.to_s)
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
else
puts "#{urls[repeat]} is a valid URL but does not work. Status Code: #{response.status_code}"