goog 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/goog +19 -22
  2. data/lib/goog.rb +1 -1
  3. metadata +1 -1
data/bin/goog CHANGED
@@ -4,19 +4,16 @@ require 'nokogiri'
4
4
  require 'cgi'
5
5
  require 'yaml'
6
6
  require 'uri'
7
+ require 'optparse'
7
8
 
8
- if ARGV[0] =~ /^-h|--help/
9
- require 'goog'
10
- puts <<END
11
- Usage: goog [-n pages] [-d date range type] [query]
12
-
13
- Synopsis:
14
- -n [pages] Return n pages of results
15
- -d [date range type] Limit results to date range (see below for codes)
16
- -h, --help Show this message
17
-
18
- Date range types for -d option:
19
-
9
+ options = {}
10
+ OptionParser.new do |opts|
11
+ opts.banner = "Usage: goog [options] [query]"
12
+ opts.on("-h", "--help", "Show this message") {
13
+ require 'goog'
14
+ puts <<END
15
+ #{opts}
16
+ DATE RANGE options for -d option:
20
17
  h last hour
21
18
  d last day (24 hours)
22
19
  w last week
@@ -27,12 +24,12 @@ goog #{Goog::VERSION}
27
24
  http://github.com/danchoi/goog
28
25
  Author: Daniel Choi <dhchoi@gmail.com>
29
26
  END
30
- exit
31
- end
32
-
33
- pages = ARGV[0] =~ /^-n/ ? (ARGV.shift && ARGV.shift[/\d+/,0].to_i) : 1
34
- date_range = ARGV[0] =~ /^-d/ ? (ARGV.shift && ARGV.shift[/[hdwmy]/,0]) : nil
35
-
27
+ exit
28
+ }
29
+ opts.on("-d", '--date-range [DATE RANGE]', 'Show results for date range. See below for options.') {|dr| options[:date_range] = dr }
30
+ opts.on("-n", '--num-pages [NUM PAGES]', 'Show NUM PAGES pages of results') {|pages| options[:pages] = pages.to_i }
31
+ opts.on("-c", '--color', 'Force color output') {options[:color] = true}
32
+ end.parse!
36
33
  query = ARGV.join(' ')
37
34
  unless query
38
35
  abort "Please provide a search query"
@@ -45,10 +42,10 @@ if RUBY_VERSION !~ /^1.9/
45
42
  abort "Requires Ruby 1.9"
46
43
  end
47
44
  query = "/search?q=#{CGI.escape query}"
48
- if date_range
49
- query += "&as_qdr=#{date_range}"
45
+ if options[:date_range]
46
+ query += "&as_qdr=#{options[:date_range]}"
50
47
  end
51
- (1..pages).each do |page|
48
+ (1..(options[:pages] || 1)).each do |page|
52
49
  if query.nil?
53
50
  exit
54
51
  end
@@ -75,7 +72,7 @@ end
75
72
  end
76
73
  end
77
74
  number = (page - 1) * 10 + (index + 1)
78
- res = if STDOUT.tty?
75
+ res = if STDOUT.tty? || options[:color]
79
76
  ["#{number}. \e[36m#{title}\e[0m", excerpt, "\e[35m#{link }\e[0m"]
80
77
  else
81
78
  ["#{number}. #{title}", excerpt, link]
data/lib/goog.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Goog
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: