Sha256: c9829cc76b15890b11a7dd01f424cca46b9658b8b52b99358595c833e769b005

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'infoboxer'

include Infoboxer

require 'optparse'

wiki_url = nil

OptionParser.new do |opts|
  opts.banner = "Usage: bin/infoboxer [-w wiki_api_url]"

  opts.on("-w", "--wiki WIKI_API_URL",
              "Make wiki by WIKI_API_URL a default wiki, and use it with just get('Pagename')") do |w|
    wiki_url = w
  end
end.parse!

if wiki_url
  if wiki_url =~ /^[a-z]+$/
    wiki_url = case
    when domain = Infoboxer::WIKIMEDIA_PROJECTS[wiki_url.to_sym]
      "https://en.#{domain}/w/api.php"
    when domain = Infoboxer::WIKIMEDIA_PROJECTS[('w' + wiki_url).to_sym]
      "https://en.#{domain}/w/api.php"
    else
      fail("Unidentified wiki: #{wiki_url}")
    end
  end
  
  DEFAULT_WIKI = Infoboxer.wiki(wiki_url)
  puts "Default Wiki selected: #{wiki_url}.\nNow you can use `get('Pagename')`, `category('Categoryname')` and so on.\n\n"
  [:raw, :get, :category, :search, :prefixsearch].each do |m|
    define_method(m){|*arg|
      DEFAULT_WIKI.send(m, *arg)
    }
  end
end

require 'irb'
ARGV.shift until ARGV.empty?
IRB.start

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
infoboxer-0.2.0 bin/infoboxer