class ValidateWebsite::Parser
Internal class for parse command line args
Constants
- DEFAULT_OPTIONS
- VALID_TYPES
Public Class Methods
boolean_options(opt)
click to toggle source
# File lib/validate_website/option_parser.rb, line 74 def self.boolean_options(opt) opt.bool('-n', '--not-found', "Log not found url (default: #{DEFAULT_OPTIONS[:not_found]})", default: DEFAULT_OPTIONS[:not_found]) opt.bool('--color', "Show colored output (default: #{DEFAULT_OPTIONS[:color]})", default: DEFAULT_OPTIONS[:color]) end
command_line_parse_crawl(_args)
click to toggle source
Parse command line for validate-website bin @params [ARGV] @return [Hash]
# File lib/validate_website/option_parser.rb, line 103 def self.command_line_parse_crawl(_args) default_args do |opt| opt.string('-s', '--site', "Website to crawl (default: #{DEFAULT_OPTIONS[:site]})", default: DEFAULT_OPTIONS[:site]) opt.string('-u', '--user-agent', 'Change user agent', default: DEFAULT_OPTIONS[:user_agent]) opt.regexp('-e', '--exclude', 'Url to exclude (ex: "redirect|news")') opt.string('-c', '--cookies', 'Set defaults cookies') end end
command_line_parse_static(_args)
click to toggle source
Parse command line for validate-website-static bin @params [ARGV] @return [Hash]
# File lib/validate_website/option_parser.rb, line 119 def self.command_line_parse_static(_args) default_args do |opt| opt.string('-s', '--site', "Website to crawl (default: #{DEFAULT_OPTIONS[:site]})", default: DEFAULT_OPTIONS[:site]) opt.string('-p', '--pattern', "Filename pattern (default: #{DEFAULT_OPTIONS[:pattern]})", default: DEFAULT_OPTIONS[:pattern]) opt.regexp('-e', '--exclude', 'Url to exclude (ex: "redirect|news")') end end
default_args() { |opt| ... }
click to toggle source
# File lib/validate_website/option_parser.rb, line 44 def self.default_args Slop.parse do |opt| yield opt if block_given? markup_syntax(opt) boolean_options(opt) ignore_html5_options(opt) verbose_option(opt) version_help(opt) end end
ignore_html5_options(opt)
click to toggle source
# File lib/validate_website/option_parser.rb, line 55 def self.ignore_html5_options(opt) opt.regexp('-i', '--ignore', 'Validation errors to ignore (ex: "valign|autocorrect")') opt.string('-x', '--html5-validator', 'Change default html5 validator engine (tidy/nu/nokogiri)', default: DEFAULT_OPTIONS[:html5_validator]) opt.string('-5', '--html5-validator-service-url', 'Change default html5 validator service URL for "nu" engine') end
markup_syntax(opt)
click to toggle source
# File lib/validate_website/option_parser.rb, line 65 def self.markup_syntax(opt) opt.bool('-m', '--markup', "Markup validation (default: #{DEFAULT_OPTIONS[:markup]})", default: DEFAULT_OPTIONS[:markup]) opt.bool('--css-syntax', "Css validation (default: #{DEFAULT_OPTIONS[:css_syntax]})", default: DEFAULT_OPTIONS[:css_syntax]) end
parse(options, type)
click to toggle source
Generic parse method for crawl or static options
# File lib/validate_website/option_parser.rb, line 32 def self.parse(options, type) raise ArgumentError unless VALID_TYPES.include?(type) # We are in command line (ARGV) if options.is_a?(Array) send("command_line_parse_#{type}", options) else # for testing or Ruby usage with a Hash DEFAULT_OPTIONS.merge(options) end end
verbose_option(opt)
click to toggle source
# File lib/validate_website/option_parser.rb, line 83 def self.verbose_option(opt) opt.bool('-v', '--verbose', "Show validator errors (default: #{DEFAULT_OPTIONS[:verbose]})", default: DEFAULT_OPTIONS[:verbose]) end
version_help(opt)
click to toggle source
# File lib/validate_website/option_parser.rb, line 89 def self.version_help(opt) opt.on('--version', 'Display version.') do puts ValidateWebsite::VERSION exit end opt.on('-h', '--help', 'Display this help message.') do puts opt exit end end