Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formula: add clap completion style #18945

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,15 @@ def extract_macho_slice_from(file, arch = Hardware::CPU.arch)
# bin/"foo")
# ```
#
# Using predefined `shell_parameter_format :clap`.
#
# ```ruby
# generate_completions_from_executable(bin/"foo", shell_parameter_format: :clap, shells: [:zsh])
#
# # translates to
# (zsh_completion/"_foo").write Utils.safe_popen_read({ "SHELL" => "zsh", "COMPLETE" => "zsh" }, bin/"foo")
# ```
#
# Using custom `shell_parameter_format`.
#
# ```ruby
Expand All @@ -2125,7 +2134,7 @@ def extract_macho_slice_from(file, arch = Hardware::CPU.arch)
# the shells to generate completion scripts for. Defaults to `[:bash, :zsh, :fish]`.
# @param shell_parameter_format
# specify how `shells` should each be passed to the `executable`. Takes either a String representing a
# prefix, or one of `[:flag, :arg, :none, :click]`. Defaults to plainly passing the shell.
# prefix, or one of `[:flag, :arg, :none, :click, :clap]`. Defaults to plainly passing the shell.
sig {
params(
commands: T.any(Pathname, String),
Expand Down Expand Up @@ -2158,6 +2167,9 @@ def generate_completions_from_executable(*commands,
prog_name = File.basename(commands.first.to_s).upcase.tr("-", "_")
popen_read_env["_#{prog_name}_COMPLETE"] = "#{shell}_source"
nil
elsif shell_parameter_format == :clap
popen_read_env["COMPLETE"] = shell.to_s
nil
else
"#{shell_parameter_format}#{shell}"
end
Expand Down
Loading