write_exec_script: add args parameter
This commit is contained in:
parent
eda9e78529
commit
1a5e62e826
@ -273,19 +273,24 @@ 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.any(String, T::Array[String])).void
|
||||||
|
}
|
||||||
|
def write_exec_script(*targets, args: T.unsafe(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
|
||||||
|
arg_str = "#{Array(args).join(" ")} " if args.present?
|
||||||
|
|
||||||
mkpath
|
mkpath
|
||||||
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user