Last active
August 29, 2015 13:55
-
-
Save AndyObtiva/8763150 to your computer and use it in GitHub Desktop.
Heroku Config Parser in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Parses configuration out from the "heroku config" command, and converts to command-line input | |
# for the "heroku config:add" command. It escapes $ characters. | |
def parse(config_text) | |
config_line_regex = /([^:]+):(.*)/ | |
config_text.split("\n").map do |line| | |
line_match = line.match(config_line_regex) | |
[line_match[1], line_match[2]] | |
end.map do |name, value| | |
"#{name.strip}=\"#{value.strip.gsub("$", "\\$")}\"" | |
end.join(" ") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment