Last active
August 29, 2015 14:04
-
-
Save pikesley/60bc5bc6f376edb158c4 to your computer and use it in GitHub Desktop.
Convert .kitchen.yml to attributes for wrapper cookbook
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
#!/usr/bin/env ruby | |
require 'yaml' | |
y = YAML.load File.open ARGV[0] | |
def walk hash, stack = [], output = [] | |
hash.each do |key, val| | |
stack << key | |
if val.is_a?(Hash) | |
walk val, stack, output | |
else | |
if not val.is_a?(Array) | |
val = "'%s'" % val | |
end | |
output << "default['%s'] = %s\n" % [ stack.join("']['"), val ] | |
stack.pop | |
end | |
end | |
stack.pop | |
output.sort | |
end | |
puts walk y['suites'][0]['attributes'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment