blob: ced5fb29b3bc684837f25e4f0201881fc127a3e0 [file] [log] [blame]
class Wunderbar::JsonBuilder
def task(title, &block)
if not @task
# dry run: collect up a list of tasks
@_target[:tasklist] ||= []
@_target[:tasklist] << {title: title, form: []}
block.call
elsif @task == title
# actual run
block.call
@task = nil
end
end
def _input *args
return if @task
@_target[:tasklist].last[:form] << ['input', '', *args]
end
def _textarea *args
return if @task
@_target[:tasklist].last[:form] << ['textarea', *args]
end
def _message mail
if @task
super
else
@_target[:tasklist].last[:form] << ['textarea', mail.to_s.strip, rows: 20]
end
end
def form &block
block.call
end
def complete &block
return unless @task
if block.arity == 1
Dir.mktmpdir do |dir|
block.call dir
end
else
block.call
end
end
def _transcript *args
return unless @task
super
end
def _backtrace *args
return unless @task
super
end
def svn *args
args << svnauth if env.password and %(checkout update commit).include?(args.first)
_.system! 'svn', *args
end
def svn!(command,path,options={})
options[:env] = env if env.password and %(checkout update commit).include?(command)
ASF::SVN.svn_!(command,path,_,options)
end
def svnauth
[
'--non-interactive',
'--no-auth-cache',
'--username', env.user.dup.untaint, # could be frozen
'--password', env.password.dup.untaint
]
end
def template(name)
path = File.expand_path("../templates/#{name}", __FILE__.untaint)
ERB.new(File.read(path.untaint).untaint).result(binding)
end
end