Sha256: fa90b01aa0c2dee8c1d3371a3a0f5d76a6b6897a0e5c00c7b9820f15856de341
Contents?: true
Size: 1.66 KB
Versions: 1
Compression:
Stored size: 1.66 KB
Contents
#!/usr/bin/env ruby require 'rubygems' require 'facebokr/version' require 'facebokr/app' require 'facebokr/shell' require 'yaml' require 'optparse' Signal.trap("SIGINT") { exit } DEFAULT_CONFIG = File.expand_path("~/.facebokr.yml") def default_options { :shell => true, :app_id => ENV["APP_ID"], :app_secret => ENV["APP_SECRET"] } end def options_from_config(config = DEFAULT_CONFIG) if File.exists?(config) Hash[YAML.load(File.read(config)).map { |k, v| [k.to_sym, v] }] else {} end end def options_from_cli options = {} OptionParser.new(ARGV) do |opts| opts.banner = "Usage: taketo [destination] [options]" opts.version = ::Facebokr::VERSION opts.separator "" opts.separator "Mandatory options:" opts.on("-i", "--app-id ID", "Facebook app id") { |v| options[:app_id] = v } opts.on("-s", "--app-secret SECRET", "Facebook app secret") { |v| options[:app_secret] = v } opts.separator "Special options:" opts.on("-c", "--command COMMAND", "Execute one-shot command") do |v| options[:shell] = false options[:command] = v end end.parse! options end options = default_options.merge(options_from_config).merge(options_from_cli) begin raise "Facebook app id not provided!" if String(options[:app_id]).empty? raise "Facebook app secret not provided!" if String(options[:app_secret]).empty? app = Facebokr::App.new(options[:app_id], options[:app_secret]) if options[:shell] Facebokr::Shell.new(app).run elsif options[:command] puts app.public_send(command) end rescue SystemExit # Do nothing rescue Exception => e $stderr.puts "An error occured: #{e.message}" exit 1 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
facebokr-0.0.3 | bin/facebokr |