Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Specify config filename #2

Closed
wants to merge 34 commits into from

9 participants

@joelvh

Specify the filename to save environment variables to with the --filename option.

@tonyxiao

+1, was looking for this feature myself

@jalada

+1 could really do with this for managing multiple .env files (e.g. .env for dev and .env_production for production)

@joelvh

Updated to use heroku-api

@xentek xentek commented on the diff
lib/config/heroku/command/config.rb
((2 lines not shown))
require "heroku/command/config"
-class Heroku::Command::Config
+class Heroku::Command::Config < Heroku::Command::Base
# config:pull
#
@xentek
xentek added a note

You might want to update the comments here with the new --filename option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@xentek xentek commented on the diff
lib/config/heroku/command/config.rb
@@ -35,14 +36,20 @@ def push
@xentek
xentek added a note

You might want to update the comments here, too, with the new --filename option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
init.rb
@@ -1 +1,6 @@
require "config/heroku/command/config"
+
+if Heroku::VERSION >= "2.0"
+ # specify a specific filename to use
+ Heroku::Command.global_option :filename, "--filename FILENAME"
@xentek
xentek added a note

This doesn't seem to add the --filename option to the output of heroku help config:pull

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@xentek

Just a heads up: when using this branch, config:pull --filename doesn't seem to overwrite an existing file. To get a new config I had to remove the file manually and then re-run it.

I didn't check the file itself (probably should have), but I assumed it either didn't write to the file because it existed or appended to it.

@joelvh joelvh closed this
@kcolton

Submitted a pull request which adds a very simple --env arg which lets you specify env filename for pushing and pulling and mirrors foreman's arg for nice symmetry.

#11

@Undistraction

Would be great to have handling similar to Foreman and Dotenv (which it uses) So that if a production-specific env file exists; .env.staging etc, it is also loaded/pushed.

@blasterpal

Is there any reason why this PR was closed or this one #11 ? @ddollar is this something you don't want in heroku-config? This feature would be arguably necessary to manage large environment configuration sets for multiple environments where source control is needed for audit purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 24, 2012
  1. added --filename option to specify env file or plain --appenv to use …

    Joel Van Horn authored
    …app name with .env extension
  2. nil fix

    Joel Van Horn authored
  3. nil fix

    Joel Van Horn authored
  4. CLI output updated

    Joel Van Horn authored
  5. added some debugging

    Joel Van Horn authored
  6. added some debugging

    Joel Van Horn authored
  7. added some debugging

    Joel Van Horn authored
  8. properly added filename and multi options

    Joel Van Horn authored
Commits on Jun 11, 2012
  1. @joelvh
  2. @joelvh
  3. @joelvh

    updated to newer gem

    joelvh authored
Commits on Jun 14, 2012
  1. @joelvh
Commits on Jul 12, 2012
  1. @joelvh

    updated instructions

    joelvh authored
Commits on Sep 12, 2012
  1. @joelvh

    updated to use heroku-api

    joelvh authored
  2. @joelvh

    updated heroku-api method names

    joelvh authored
  3. @joelvh
  4. @joelvh

    reuse remote_config method

    joelvh authored
Commits on Sep 28, 2012
  1. @nicholasjhenry
  2. @nicholasjhenry
  3. Merge pull request #4 from nicholasjhenry/master

    authored
    Small correction to README
  4. Revert "Merge pull request #4 from nicholasjhenry/master"

    authored
    This reverts commit 5e5dac6, reversing
    changes made to 561d592.
  5. @nicholasjhenry

    Upgrade to use the Heroku API

    nicholasjhenry authored
    * This eliminates the various 'DEPRECATED' notices caused by using the Heroku::Client with recent versions of the Heroku gem
    * Fixes issue #3
Commits on Oct 26, 2012
  1. @nicholasjhenry

    Update error message

    nicholasjhenry authored
Commits on Nov 26, 2012
  1. @nicholasjhenry
Commits on Jan 25, 2013
  1. Merge pull request #6 from nicholasjhenry/upgrade-to-api

    authored
    Upgrade to use the Heroku API
  2. Merge pull request #7 from nicholasjhenry/readme-fix

    authored
    Correct description for overwrite example
Commits on Aug 25, 2013
  1. @joelvh

    added filename parameter comments, rename and delete existing file to…

    joelvh authored
    … ensure new vars get written
  2. @joelvh

    write temp file then rename

    joelvh authored
  3. @joelvh

    debug

    joelvh authored
  4. @joelvh

    debug

    joelvh authored
  5. @joelvh

    removed alias

    joelvh authored
  6. @joelvh

    removed debugging, added alias

    joelvh authored
  7. @joelvh

    merged in upstream

    joelvh authored
  8. @joelvh

    removed env and option

    joelvh authored
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -0,0 +1 @@
+.project
View
3  README.md
@@ -6,12 +6,13 @@ Provides a way for you to push/pull your Heroku environment to use locally.
Add the heroku gem plugin:
- $ heroku plugins:install git://github.com/ddollar/heroku-config.git
+ $ heroku plugins:install git://github.com/joelvh/heroku-config.git
heroku-config installed
Add the following to `.gitignore`:
.env
+ *.env
## Usage
View
16 init.rb
@@ -1 +1,17 @@
require "config/heroku/command/config"
+
+if Heroku::VERSION >= "2.0"
+ # specify a specific filename to use
+ #Heroku::Command.global_option :filename, "-f", "--filename FILENAME"
+end
+
+begin
+ require "heroku-api"
+rescue LoadError
+ puts <<-MSG
+ heroku-config - requires the heroku-api gem. Please install:
+
+ gem install heroku-api
+ MSG
+ exit
+end
View
36 lib/config/heroku/command/config.rb
@@ -1,6 +1,7 @@
+require "heroku/command/base"
require "heroku/command/config"
-class Heroku::Command::Config
+class Heroku::Command::Config < Heroku::Command::Base
# config:pull
#
@xentek
xentek added a note

You might want to update the comments here with the new --filename option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@@ -10,6 +11,7 @@ class Heroku::Command::Config
#
# -i, --interactive # prompt whether to overwrite each config var
# -o, --overwrite # overwrite existing config vars
+ # -f, --filename # specify a filename to use instead of ".env"
#
def pull
interactive = options[:interactive]
@@ -17,7 +19,7 @@ def pull
config = merge_config(remote_config, local_config, interactive, overwrite)
write_local_config config
- display "Config for #{app} written to .env"
+ display "Config for #{app} written to #{filename}"
end
# config:push
@@ -28,6 +30,7 @@ def pull
#
# -i, --interactive # prompt whether to overwrite each config var
# -o, --overwrite # overwrite existing config vars
+ # -f, --filename # specify a filename to use instead of ".env"
#
def push
interactive = options[:interactive]
@@ -35,14 +38,20 @@ def push
config = merge_config(local_config, remote_config, interactive, overwrite)
write_remote_config config
- display "Config in .env written to #{app}"
+ display "Config in #{filename} written to #{app}"
end
private ######################################################################
+ def filename
+ name = options[:filename]
+ return name unless name.nil? || name.empty?
+ ".env"
+ end
+
def local_config
- File.read(".env").split("\n").inject({}) do |hash, line|
- if line =~ /\A([A-Za-z0-9_]+)=(.*)\z/
+ File.read(filename).split("\n").inject({}) do |hash, line|
+ if line =~ /\A([A-Za-z_0-9]+)=(.*)\z/
hash[$1] = $2
end
hash
@@ -52,26 +61,33 @@ def local_config
end
def remote_config
- heroku.config_vars(app)
+ api.get_config_vars(app).body
end
def write_local_config(config)
- File.open(".env", "w") do |file|
+ temp_filename = "#{filename}.#{Time.now.utc.to_i}.tmp"
+
+ File.open(temp_filename, "w") do |file|
config.keys.sort.each do |key|
file.puts "#{key}=#{config[key]}"
end
end
+
+ File.delete(filename) if File.exists?(filename)
+
+ File.rename(temp_filename, filename)
+
end
def write_remote_config(config)
- remote_config = heroku.config_vars(app)
+ remote_config_vars = remote_config
add_config_vars = config.inject({}) do |hash, (key,val)|
- hash[key] = val unless remote_config[key] == val
+ hash[key] = val unless remote_config_vars[key] == val
hash
end
- heroku.add_config_vars(app, add_config_vars)
+ api.put_config_vars(app, add_config_vars)
end
def merge_config(source, target, interactive=false, overwrite=false)
Something went wrong with that request. Please try again.