Hashar has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/55304


Change subject: erb expander for testing purposes
......................................................................

erb expander for testing purposes

This script let you expand an ERB template from the command line
while optionally passing variables that will be expanded in the
template.  Really useful when you are hacking an erb template. It
probably does not support passing an array as a value though :(

Change-Id: If820ccf06877e48087cd82be67f1df2f68512db2
---
A expanderb.rb
1 file changed, 68 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/04/55304/1

diff --git a/expanderb.rb b/expanderb.rb
new file mode 100755
index 0000000..11d0ad1
--- /dev/null
+++ b/expanderb.rb
@@ -0,0 +1,68 @@
+#!/usr/bin/env ruby
+#
+# This script let you expand an ERB template from the command line
+# while optionally passing variables that will be expanded in the
+# template.
+#
+# Joint copyright:
+# Copyright 2012, Antoine "hashar" Musso
+# Copyright 2012, Wikimedia Foundation
+
+# Command line option parsing library
+require 'optparse'
+require 'erb'
+
+# Filename of the ERB template we are going to expand
+$filename = nil
+
+# Parsing the options
+optparse = OptionParser.new do |opts|
+
+       opts.banner = "Usage: expanderb.rb -f FILENAME [key=val [key2=val]]"
+
+       opts.on( '-f', '--filename FILENAME', 'ERB filename to expand') do |f|
+               $filename = f
+       end
+
+       opts.on_tail( '-h', '--help', 'Show this message' ) do
+               puts opts
+               exit
+       end
+end
+
+# Parse command line options
+begin
+       # -f is mandatory
+       optparse.parse!
+       if $filename.nil?
+               puts "You must specify an ERB filename"
+               puts optparse
+               exit
+       end
+rescue
+       # Catch all
+       puts $!.to_s
+       puts optparse
+       exit
+end
+
+template_values = {}
+ARGV.each do |val|
+       key, value = val.split( '=' )
+       template_values[key] = value
+end
+p template_values
+
+def get_values(key)
+       template_values[key]
+end
+
+
+# Parse template
+begin
+       template = ERB.new(File.read($filename))
+       p template.result(get_values)
+rescue
+       p "Something went wrong, usually because you are missing a variable."
+       p $!.to_s
+end

-- 
To view, visit https://gerrit.wikimedia.org/r/55304
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If820ccf06877e48087cd82be67f1df2f68512db2
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Hashar <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to