From 792fc1fe7ccdf78552acd2e5974532830113d5f6 Mon Sep 17 00:00:00 2001 From: Jonah Hirsch Date: Fri, 30 Jun 2017 13:15:55 -0700 Subject: [PATCH] Support heroku config --json ONLY --- README.md | 2 +- lib/envied/cli.rb | 15 ++++++--------- lib/envied/templates/heroku-env-check.tt | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ec56eff..38a2b96 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,7 @@ It assumes a standard project layout (see the default value for the globs-option The easiest/quickest is to run: ``` -$ heroku config | bundle exec envied check:heroku +$ heroku config --json | bundle exec envied check:heroku ``` This is equivalent to having the heroku config as your local environment and running `envied check:heroku --groups default production`. diff --git a/lib/envied/cli.rb b/lib/envied/cli.rb index c3cfef9..bb8c40b 100644 --- a/lib/envied/cli.rb +++ b/lib/envied/cli.rb @@ -1,4 +1,5 @@ require 'thor' +require 'json' require 'envied/env_var_extractor' class ENVied @@ -84,7 +85,7 @@ def check The Heroku config should be piped to this task: - heroku config | bundle exec envied check:heroku + heroku config --json | bundle exec envied check:heroku Use the check:heroku:binstub-task to turn this into a bash-script. @@ -96,16 +97,12 @@ def check define_method "check:heroku" do if STDIN.tty? error <<-ERR -Please pipe the contents of `heroku config` to this task. -I.e. `heroku config | bundle exec envied check:heroku`" +Please pipe the contents of `heroku config --json` to this task. +I.e. `heroku config --json | bundle exec envied check:heroku`" ERR exit 1 end - config = STDIN.read - heroku_env = Hash[config.split("\n")[1..-1].each_with_object([]) do |i, res| - res << i.split(":", 2).map(&:strip) - end] - + heroku_env = JSON.parse(STDIN.read) ENV.replace({}).update(heroku_env) requested_groups = ENV['ENVIED_GROUPS'] || options[:groups] @@ -119,7 +116,7 @@ def check long_desc <<-LONG Generates a shell script to check the Heroku config against the local Envfile. - The same as the check:heroku-task, but all in one script (no need to pipe `heroku config` to it etc.). + The same as the check:heroku-task, but all in one script (no need to pipe `heroku config --json` to it etc.). LONG option :dest, banner: "where to put the script", desc: "Default: bin/-env-check or bin/heroku-env-check" diff --git a/lib/envied/templates/heroku-env-check.tt b/lib/envied/templates/heroku-env-check.tt index d7be587..7afb2b3 100644 --- a/lib/envied/templates/heroku-env-check.tt +++ b/lib/envied/templates/heroku-env-check.tt @@ -3,7 +3,7 @@ # Check the config of a Heroku app against the defined variables in `Envfile` <%- if @app %> -HEROKU_APP=<%= @app %> exec heroku config | bundle exec envied check:heroku --groups <%= @groups.join(" ") %> +HEROKU_APP=<%= @app %> exec heroku config --json | bundle exec envied check:heroku --groups <%= @groups.join(" ") %> <%- else %> -exec heroku config | bundle exec envied check:heroku --groups <%= @groups.join(" ") %> +exec heroku config --json | bundle exec envied check:heroku --groups <%= @groups.join(" ") %> <%- end %>