#!/usr/bin/env ruby require 'getoptlong' require_relative '../lib/rdoc_link_checker' options = GetoptLong.new( ['--html_dirpath', '-d', GetoptLong::REQUIRED_ARGUMENT], ['--onsite_only', '-l', GetoptLong::NO_ARGUMENT], ['--no_toc', '-n', GetoptLong::NO_ARGUMENT], ['--version', '-v', GetoptLong::NO_ARGUMENT], ['--help', '-h', GetoptLong::NO_ARGUMENT] ) def help path = File.absolute_path(__FILE__) dirname = File.dirname(File.dirname(path)) filepath = File.join(dirname, 'doc', 'help.txt') puts File.read(filepath) exit end def version puts RDocLinkChecker::VERSION exit end onsite_only = false no_toc = false options.each do |option, argument| case option when '--onsite_only' onsite_only = true when '--no_toc' no_toc = true when '--help' help when '--version' version end end message = nil case ARGV.size when 0 message = "Expected one argument; got none." when 1 # Okay. else message = "Expected one argument, not #{ARGV.inspect}." end raise ArgumentError.new(message) if message html_dirpath = ARGV[0] RDocLinkChecker.new( html_dirpath, onsite_only: onsite_only, no_toc: no_toc ).check