write_exec_script: add args parameter

This commit is contained in:
Eric Knibbe 2025-09-01 14:30:43 -04:00
parent 47e07fb269
commit c1337e4946
No known key found for this signature in database

View File

@ -273,19 +273,30 @@ class Pathname
end end
# Writes an exec script in this folder for each target pathname. # Writes an exec script in this folder for each target pathname.
sig { params(targets: T.any(T::Array[T.any(String, Pathname)], String, Pathname)).void } sig {
def write_exec_script(*targets) params(targets: T.any(T::Array[T.any(String, Pathname)], String, Pathname),
args: T.nilable(T.any(String, T::Array[String]))).void
}
def write_exec_script(*targets, args: nil)
targets.flatten! targets.flatten!
if targets.empty? if targets.empty?
opoo "Tried to write exec scripts to #{self} for an empty list of targets" opoo "Tried to write exec scripts to #{self} for an empty list of targets"
return return
end end
mkpath mkpath
args = if args.is_a?(Array)
args.join(" ")
elsif args.is_a?(String)
args
end
arg_str = "#{args} " if args.present?
targets.each do |target| targets.each do |target|
target = Pathname.new(target) # allow pathnames or strings target = Pathname.new(target) # allow pathnames or strings
join(target.basename).write <<~SH join(target.basename).write <<~SH
#!/bin/bash #!/bin/bash
exec "#{target}" "$@" exec "#{target}" #{arg_str}"$@"
SH SH
end end
end end