Class: ValidateWebsite::Parser
- Inherits:
-
Object
- Object
- ValidateWebsite::Parser
- Defined in:
- lib/validate_website/option_parser.rb
Constant Summary collapse
- DEFAULT_OPTS_ALL =
{ :markup_validation => true, # crawler: log not found url (404 status code) # static: log not found url (not on filesystem, pwd considered as root « / ») :not_found => false, :quiet => false, :file => nil, # regex to ignore certain validation errors :ignore_errors => nil, :color => true, # internal verbose for ValidateWebsite :validate_verbose => false, # Anemone options see anemone/lib/anemone/core.rb :verbose => false, :cookies => nil, :accept_cookies => true, :redirect_limit => 0, }
- DEFAULT_OPTS_CRAWL =
{ :site => 'http://localhost:3000/', :exclude => nil, }.merge(DEFAULT_OPTS_ALL)
- DEFAULT_OPTS_STATIC =
{ :site => 'http://www.example.com/', :pattern => '**/*.html', }.merge(DEFAULT_OPTS_ALL)
Class Method Summary collapse
- .command_line_parse!(opts, args, options) ⇒ Object
- .command_line_parse_crawl(args) ⇒ Object
- .command_line_parse_static(args) ⇒ Object
- .parse(options, type) ⇒ Object
Class Method Details
.command_line_parse!(opts, args, options) ⇒ Object
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/validate_website/option_parser.rb', line 155 def self.command_line_parse!(opts, args, ) begin opts.parse!(args) rescue OptionParser::InvalidOption, OptionParser::MissingArgument puts $!.to_s puts opts exit 128 end @@default_opts.merge() end |
.command_line_parse_crawl(args) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/validate_website/option_parser.rb', line 48 def self.command_line_parse_crawl(args) = {} opts = OptionParser.new do |o| o.set_summary_indent(' ') o. = 'Usage: validate-website [OPTIONS]' o.define_head 'validate-website - Web crawler for checking the ' + 'validity of your documents' o.separator '' o.on("-s", "--site 'SITE'", String, "Website to crawl (Default: #{@@default_opts[:site]})") { |v| [:site] = v } o.on("-u", "--user-agent 'USERAGENT'", String, "Change user agent") { |v| [:user_agent] = v } o.on("-e", "--exclude 'EXCLUDE'", String, "Url to exclude (ex: 'redirect|news')") { |v| [:exclude] = v } o.on("-f", "--file 'FILE'", String, "Save not well formed or not found urls") { |v| [:file] = v } o.on("-c", "--cookies 'COOKIES'", String, "Set defaults cookies") { |v| [:cookies] = v } o.on("-m", "--[no-]markup-validation", "Markup validation (Default: #{@@default_opts[:markup_validation]})") { |v| [:markup_validation] = v } o.on("-i", "--ignore-errors 'IGNORE'", String, "Validation errors to ignore (regex)") { |v| [:ignore_errors] = v } o.on("-n", "--not-found", "Log not found url (Default: #{@@default_opts[:not_found]})") { |v| [:not_found] = v } o.on("--[no-]color", "Show colored output (Default: #{@@default_opts[:color]})") { |v| [:color] = v } o.on("-v", "--verbose", "Show validator errors (Default: #{@@default_opts[:validate_verbose]})") { |v| [:validate_verbose] = v } o.on("-q", "--quiet", "Only report errors (Default: #{@@default_opts[:quiet]})") { |v| [:quiet] = v } o.on("-d", "--debug", "Show anemone log (Default: #{@@default_opts[:verbose]})") { |v| [:verbose] = v } o.separator "" o.on_tail("-h", "--help", "Show this help message.") { puts o; exit } end command_line_parse!(opts, args, ) end |
.command_line_parse_static(args) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/validate_website/option_parser.rb', line 114 def self.command_line_parse_static(args) = {} opts = OptionParser.new do |o| o.set_summary_indent(' ') o. = 'Usage: validate-website-static [OPTIONS]' o.define_head 'validate-website-static - check the validity of ' + 'your documents' o.separator '' o.on("-s", "--site 'SITE'", String, "Where static files will be hosted (Default: #{@@default_opts[:site]})") { |v| [:site] = v } o.on("-p", "--pattern 'PATTERN'", String, "Change filenames pattern (Default: #{@@default_opts[:pattern]})") { |v| [:pattern] = v.strip } o.on("-f", "--file 'FILE'", String, "Save not well formed urls") { |v| [:file] = v } o.on("-m", "--[no-]markup-validation", "Markup validation (Default: #{@@default_opts[:markup_validation]})") { |v| [:markup_validation] = v } o.on("-n", "--not-found", "Log files not on filesystem, pwd considered as root « / » (Default: #{@@default_opts[:not_found]})") { |v| [:not_found] = v } o.on("-v", "--verbose", "Show validator errors (Default: #{@@default_opts[:validate_verbose]})") { |v| [:validate_verbose] = v } o.on("-q", "--quiet", "Only report errors (Default: #{@@default_opts[:quiet]})") { |v| [:quiet] = v } end command_line_parse!(opts, args, ) end |
.parse(options, type) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/validate_website/option_parser.rb', line 35 def self.parse(, type) if const_defined?("DEFAULT_OPTS_#{type.to_s.upcase}") @@default_opts = const_get("DEFAULT_OPTS_#{type.to_s.upcase}") if Array === send("command_line_parse_#{type}", ) else @@default_opts.merge() end else raise ArgumentError, "Unknown options type : #{type}" end end |