Skip to content

Commit d746234

Browse files
authored
Merge pull request #20351 from Homebrew/fix_pathname_types
extend/pathname: fix type signature for write_env_script.
2 parents 53b9006 + ea53fdc commit d746234

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

Library/Homebrew/extend/pathname.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,27 @@ def write_exec_script(*targets)
289289
end
290290

291291
# Writes an exec script that sets environment variables.
292-
sig { params(target: Pathname, args: T.any(T::Array[String], T::Hash[String, String]), env: T.nilable(T::Hash[String, String])).void }
293-
def write_env_script(target, args, env = nil)
294-
unless env
295-
env = args
296-
args = nil
292+
sig {
293+
params(target: Pathname,
294+
args_or_env: T.any(String, T::Array[String], T::Hash[String, String], T::Hash[Symbol, String]),
295+
env: T.any(T::Hash[String, String], T::Hash[Symbol, String])).void
296+
}
297+
def write_env_script(target, args_or_env, env = T.unsafe(nil))
298+
args = if env.nil?
299+
env = args_or_env if args_or_env.is_a?(Hash)
300+
301+
nil
302+
elsif args_or_env.is_a?(Array)
303+
args_or_env.join(" ")
304+
else
305+
T.cast(args_or_env, T.nilable(String))
297306
end
307+
298308
env_export = +""
299309
env.each { |key, value| env_export << "#{key}=\"#{value}\" " }
310+
300311
dirname.mkpath
312+
301313
write <<~SH
302314
#!/bin/bash
303315
#{env_export}exec "#{target}" #{args} "$@"

0 commit comments

Comments
 (0)