Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

Pending tests.

[ci skip]
  • Loading branch information...
commit e785c0f6bd83b92aeb19d941e03185337ccf2cc4 1 parent 9bbc734
Steve Richert authored
5 bin/figaro
View
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+require "figaro/cli"
+
+Figaro::CLI.start
2  figaro.gemspec
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
25 lib/figaro/cli.rb
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
25 lib/figaro/cli/heroku_set.rb
View
@@ -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
27 lib/figaro/cli/task.rb
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
Please sign in to comment.
Something went wrong with that request. Please try again.