Pathname: add exec and jar helpers

Closes Homebrew/homebrew#13318.
This commit is contained in:
Adam Vandenberg 2012-08-07 11:16:45 -07:00
parent 267ffddbd3
commit 73b3977ab4

View File

@ -348,6 +348,30 @@ class Pathname
end end
end end
end end
# Writes an exec script in this folder for each target pathname
def write_exec_script *targets
targets = [targets].flatten
if targets.empty?
opoo "tried to write exec sripts to #{self} for an empty list of targets"
end
targets.each do |target|
target = Pathname.new(target) # allow pathnames or strings
(self+target.basename()).write <<-EOS.undent
#!/bin/bash
exec "#{target}" "$@"
EOS
end
end
# Writes an exec script that invokes a java jar
def write_jar_script target_jar, script_name, java_opts=""
(self+script_name).write <<-EOS.undent
#!/bin/bash
exec java #{java_opts} -jar #{target_jar} "$@"
EOS
end
end end
# sets $n and $d so you can observe creation of stuff # sets $n and $d so you can observe creation of stuff