#!/usr/bin/env ruby $LOAD_PATH << './lib' require 'optparse' require 'web_grep' options = {} OptionParser.new do |opt| opt.banner = "Usage:\n web_grep WORD WEB_PAGE [OPTIONS]" opt.separator '' opt.separator 'Options' opt.on('-w', '--word [word]', String, 'Searcheble word or RegExp') do |word| options[:word] = word end opt.on('-f', '--file [file_path]', String, 'Search in file: "../index.html"') do |file| options[:file] = file end opt.on('-u', '--url [url]', String, 'Search in URL: "ya.ru"') do |url| options[:url] = url end opt.on_tail('-v', '--version', 'Show version') do puts WebGrep::VERSION exit end opt.on_tail('-h', '--help', 'Show this help') { puts opt; exit } if ARGV.empty? && options.empty? opt.on { puts opt; exit } end end.parse! greped = WebGrep::Grep.new( word: options[:word] || ARGV[0], url: options[:url ] || ARGV[1], file: options[:file] ).grep! puts greped puts "#{"\033[32;1m"}Found #{greped.count}#{"\033[0m"}"