#!/usr/bin/env ruby $:.push File.expand_path("../../lib", __FILE__) require 'version' require 'flattr' require 'launchy' require 'commander/import' program :name, "git flattr" program :description, "Easily flattr GitHub repositories from the CLI" program :version, VERSION program :help, 'Author', 'Simon Gate ' default_command :help def error message puts "Error: #{message}" end class Git class < "#{Dir.pwd}/.git", :config => "#{Dir.pwd}/.git/config" } unless File.exists?(git_opts[:dir]) error "Don't seem to be a git repository" exit 1 end unless File.exists?(git_opts[:config]) error "Git .config file not found" exit 1 end unless Git.github_repository? error "Not a GitHub repository" exit 1 end end end end module Auth class < e puts e.message puts "Seems like you are missing a Flattr access token." puts "Browse to http://git-flattr.herokuapp.com and follow the instructions" token = ask("Token: ") end if token.nil? error "Invalid access token" exit 1 end Git.set_config "flattr.token", token.chomp end end end Flattr.configure do |config| config.access_token = Git.config 'flattr.token' end command :repo do |c| c.syntax = "git flattr repo" c.description = "Flattr the repository" c.action do |args, options| begin Git.valid? if !Auth.is_authed? Auth.do! end flattr = Flattr.new flattr.flattr Git.github_url thing = flattr.thing_lookup Git.github_url puts "Flattred #{Git.github_url} (#{thing.link})!" exit 0 rescue Flattr::Error::Unauthorized => e error e.message exit 1 rescue Flattr::Error::Forbidden => e error e.message exit 1 end end end command :commit do |c| c.syntax = "git flattr commit [commit]" c.description = "Flattr a commit" c.action do |args, opts| begin Git.valid? if !Auth.is_authed? Auth.do! end ARGV.shift end end end