@@ -38,12 +38,24 @@ def file_or_stdin(args, stdin = ::STDIN)
3838
3939def main
4040 options = OpenStruct . new
41+ options . yamls = [ ]
4142
4243 parser = OptionParser . new do |opts |
4344 opts . banner = 'Usage: %s [options] file.erb' % $0
44- opts . on '-y' , '--yaml=YAML-FILE' , 'YAML file to populate local variables for the template' do |yaml_file |
45- File . open yaml_file , 'r' do |f |
46- options . yaml = YAML ::load ( f )
45+ opts . on '-y' , '--yaml=YAML-FILE(S)' , Array , 'YAML file(s) to populate local variables for the template. separated by comma' do |configs |
46+ configs . each do |config |
47+ if File . directory? ( config )
48+ Dir . foreach ( config ) do |yaml |
49+ next if yaml == '.' or yaml == '..'
50+ File . open File . join ( config , yaml ) , 'r' do |f |
51+ options . yamls . push ( YAML ::load ( f ) )
52+ end
53+ end
54+ else
55+ File . open config , 'r' do |f |
56+ options . yamls . push ( YAML ::load ( f ) )
57+ end
58+ end
4759 end
4860 end
4961 end
@@ -53,6 +65,16 @@ def main
5365 exit 1
5466 end
5567
68+ options . yamls . each_with_index do |y , i |
69+ if !y . nil? && y . inspect != 'false'
70+ if options . yaml . nil?
71+ options . yaml = y
72+ else
73+ options . yaml = options . yaml . merge y
74+ end
75+ end
76+ end
77+
5678 file_or_stdin args do |input |
5779 puts ERBContext . render ( options . yaml || { } , input . read , nil , '-' )
5880 end
0 commit comments