Sha256: d0c60b601cc5ad11c60ae076a9f902888d804d1a3659eddf0cbb7b87b7e88232

Contents?: true

Size: 902 Bytes

Versions: 1

Compression:

Stored size: 902 Bytes

Contents

#!/usr/bin/env ruby

# Google search CLI browser that can open links into a browser.

require 'bundler/setup'
require 'slop'

require_relative '../lib/google-browse'

# Manage CLI options.
results_per_page = GoogleBrowse::Browser::DEFAULT_RESULTS_PER_PAGE
opts = Slop.parse help: true do
  banner "Usage: #{File.basename $0} [options] ['QUERY-STRING']"

  on 'n=', 'number=', 
    "Number of results per page (default: #{results_per_page})",
    as: Integer, default: results_per_page
end

exit 0 if opts.help?

def cli_error(opts, message)
  puts "ERROR: #{message}"
  puts
  puts opts
  exit 0
end

cli_error opts, 'Must have 1 or more results per page!' unless opts[:number] >= 1

# BUG: No idea why the -n option STAYS in argv ;(
query = ARGV.empty? ? nil : ARGV.join(" ")

puts
puts "Google Browse v#{GoogleBrowse::VERSION}"

GoogleBrowse.search query: query, results_per_page: opts[:number]





Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
google-browse-0.1.2 bin/google-browse