#!/usr/bin/env ruby $:.push File.expand_path("../../lib", __FILE__) require 'git-flattr' 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 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 rescue Flattr::Error::Forbidden => e error e.message 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 commit = ARGV.shift if commit.nil? error "No commit supplied" end commit = Git.commit commit if !commit error "Commit does not exist in this repository" end commit_url = "#{Git.github_url}/commit/#{commit}" flattr = Flattr.new puts commit_url flattr.flattr commit_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 rescue Flattr::Error::Forbidden => e error e.message end end end command :info do |c| c.syntax = "git flattr info" c.description = "Information about the current repository" c.action do |args, opts| Git.valid? flattr = Flattr.new thing = flattr.thing_lookup Git.github_url if thing puts "[#{thing.flattrs}] flattrs, #{thing.title} ( #{thing.url} )" else puts "This GitHub repo is not on Flattr." end end end