Permalink
Browse files

Start to convert the heroku Rake task to a heroku:set Thor task

Pending tests.

[ci skip]
  • Loading branch information...
1 parent 9bbc734 commit e785c0f6bd83b92aeb19d941e03185337ccf2cc4 @laserlemon committed Jan 7, 2014
Showing with 84 additions and 0 deletions.
  1. +5 −0 bin/figaro
  2. +2 −0 figaro.gemspec
  3. +25 −0 lib/figaro/cli.rb
  4. +25 −0 lib/figaro/cli/heroku_set.rb
  5. +27 −0 lib/figaro/cli/task.rb
View
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+require "figaro/cli"
+
+Figaro::CLI.start
View
@@ -18,4 +18,6 @@ Gem::Specification.new do |gem|
gem.files = `git ls-files`.split($\)
gem.test_files = gem.files.grep(/^spec/)
+
+ gem.executables << "figaro"
end
View
@@ -0,0 +1,25 @@
+require "thor"
+
+require "figaro/cli/heroku_set"
+
+module Figaro
+ class CLI < Thor
+ desc "heroku:set", "Send Figaro configuration to Heroku"
+
+ option "app",
+ aliases: ["a"],
+ desc: "Specify a Heroku app"
+ option "environment",
+ aliases: ["e"],
+ default: "development",
+ desc: "Specify an application environment"
+ option "path",
+ aliases: ["p"],
+ default: "config/application.yml",
+ desc: "Specify a configuration file path"
+
+ define_method "heroku:set" do
+ HerokuSet.run(options)
+ end
+ end
+end
@@ -0,0 +1,25 @@
+require "figaro/cli/task"
+
+module Figaro
+ class CLI < Thor
+ class HerokuSet < Task
+ def run
+ system(configuration, command)
+ end
+
+ private
+
+ def command
+ "heroku config:set #{for_app} #{vars}"
+ end
+
+ def for_app
+ options[:app] ? "--app #{options[:app]}" : nil
+ end
+
+ def vars
+ configuration.keys.map { |k| %(#{k}="$#{k}") }.join(" ")
+ end
+ end
+ end
+end
View
@@ -0,0 +1,27 @@
+require "figaro/application"
+
+module Figaro
+ class CLI < Thor
+ class Task
+ attr_reader :options
+
+ def self.run(options = {})
+ new(options).run
+ end
+
+ def initialize(options = {})
+ @options = options
+ end
+
+ private
+
+ def configuration
+ application.configuration
+ end
+
+ def application
+ @application ||= Figaro::Application.new(options)
+ end
+ end
+ end
+end

0 comments on commit e785c0f

Please sign in to comment.