switch to more flexible shell_prefix arg

This commit is contained in:
Max Eisner 2022-07-13 14:11:17 +02:00
parent ad5a1a8138
commit 32b68838f9
No known key found for this signature in database
GPG Key ID: 4BF122C22879F0C8

View File

@ -1635,13 +1635,14 @@ class Formula
# @param shell_as_flag [Boolean] specify if `shells` should each be passed as flags to the `binary`.
# Defaults to `false`.
sig {
params(base_name: String, shells: T::Array[Symbol], binary: Pathname, cmd: String, shell_as_flag: T::Boolean).void
params(base_name: String, shells: T::Array[Symbol], binary: Pathname, cmd: String,
shell_prefix: T.nilable(T.any(Symbol, String))).void
}
def generate_completions(base_name: name,
shells: [:bash, :zsh, :fish],
binary: bin/base_name,
cmd: "completion",
shell_as_flag: false)
shell_prefix: nil)
completion_script_path_map = {
bash: bash_completion/base_name,
zsh: zsh_completion/"_#{base_name}",
@ -1650,7 +1651,14 @@ class Formula
shells.each do |shell|
script_path = completion_script_path_map[shell]
shell_parameter = shell_as_flag ? "--#{shell}" : shell.to_s
shell_parameter = if shell_prefix.nil?
shell.to_s
elsif shell_prefix == :flag
"--#{shell}"
else
"#{shell_prefix}#{shell}"
end
script_path.dirname.mkpath
script_path.write Utils.safe_popen_read(binary, cmd, shell_parameter)
end