Sha256: 0fd37149d56c425cf47c484e45a70b04fcb9fb761d4d731038088ce5e90c9fc3
Contents?: true
Size: 1.71 KB
Versions: 1
Compression:
Stored size: 1.71 KB
Contents
#!/usr/bin/env ruby # frozen_string_literal: true # for dev purposes require 'bundler/setup' if ENV['VERIFY_URLS_GEM_DEV'] require 'verify_urls' require 'verify_urls/cli' options = VerifyUrls::CLI.parse(argv: ARGV) file_path = options.fetch(:file) { raise(ArgumentError, '--file is required') } file_format = options[:format] helper = VerifyUrls::Helper reader = VerifyUrls::Reader.new(file_path, file_format) urls = reader.urls failed_urls = [] success_urls = [] skipped_urls = [] puts "Found #{urls.length} URLs in README.md" urls.each do |url| unless helper.absolute_url?(url) # Consider validating internal links such as: "#license" and "LICENSE" puts "[Skipped] #{url}.. not an absolute URL!" skipped_urls << url next end print "[Fetching] #{url}.." response = helper.GET(url) if helper.response_success?(response) puts "#{response.code} #{response.reason}!" success_urls << url else puts "#{response&.code} #{response&.reason || 'error'}!" failed_urls << url end end if file_path = options[:output] csv_string = CSV.generate do |csv| csv << %w[success failed checked skipped url] failed_urls.each { |url| csv << [false, true, true, false, url] } success_urls.each { |url| csv << [true, false, true, false, url] } skipped_urls.each { |url| csv << [false, false, false, true, url] } end File.write(file_path, csv_string) end puts puts '[Finished]' puts "Found #{urls.length}" puts "Checked #{failed_urls.length + success_urls.length}" puts "Skipped #{skipped_urls.length}" puts "Failed #{failed_urls.length}" if options.fetch(:error_failed, false) && failed_urls.length > 0 puts puts "[ERROR] #{failed_urls} URL(s) failed!" exit 1 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
verify_urls-0.1.0 | exe/verify_urls |