From 32b68838f9e5518d5b5dff64f183e942744c63cc Mon Sep 17 00:00:00 2001 From: Max Eisner <4730112+max-ae@users.noreply.github.com> Date: Wed, 13 Jul 2022 14:11:17 +0200 Subject: [PATCH] switch to more flexible shell_prefix arg --- Library/Homebrew/formula.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 6353483f21..4de200ddeb 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -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