add DSL to generate completions

This commit is contained in:
Max Eisner 2022-07-10 15:24:14 +02:00
parent 8dd96ae8ba
commit 3483ee72d5
No known key found for this signature in database
GPG Key ID: 4BF122C22879F0C8

View File

@ -1625,6 +1625,21 @@ class Formula
end
private :extract_macho_slice_from
def generate_completions(base_name = name, shells = [:bash, :zsh, :fish], binary = bin/base_name, cmd = "completion", shell_as_flag = false)
completion_script_path_map = {
:bash => bash_completion/base_name,
:zsh => zsh_completion/"_#{base_name}",
:fish => fish_completion/"#{base_name}.fish",
}
shells.each do |shell|
script_path = completion_script_path_map[shell]
shell_parameter = shell_as_flag ? "--#{shell.to_s}" : shell.to_s
script_path.dirname.mkpath
script_path.write Utils.safe_popen_read(binary, cmd, shell_parameter)
end
end
# an array of all core {Formula} names
# @private
def self.core_names