write_exec_script: add args parameter

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

View File

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