Merge pull request #18945 from daeho-ro/clap-completion
formula: add clap completion style
This commit is contained in:
commit
39a40e9873
@ -2105,6 +2105,15 @@ class Formula
|
|||||||
# bin/"foo")
|
# 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`.
|
# Using custom `shell_parameter_format`.
|
||||||
#
|
#
|
||||||
# ```ruby
|
# ```ruby
|
||||||
@ -2126,7 +2135,7 @@ class Formula
|
|||||||
# the shells to generate completion scripts for. Defaults to `[:bash, :zsh, :fish]`.
|
# the shells to generate completion scripts for. Defaults to `[:bash, :zsh, :fish]`.
|
||||||
# @param shell_parameter_format
|
# @param shell_parameter_format
|
||||||
# specify how `shells` should each be passed to the `executable`. Takes either a String representing a
|
# 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 {
|
sig {
|
||||||
params(
|
params(
|
||||||
commands: T.any(Pathname, String),
|
commands: T.any(Pathname, String),
|
||||||
@ -2164,6 +2173,9 @@ class Formula
|
|||||||
prog_name = File.basename(executable).upcase.tr("-", "_")
|
prog_name = File.basename(executable).upcase.tr("-", "_")
|
||||||
popen_read_env["_#{prog_name}_COMPLETE"] = "#{shell}_source"
|
popen_read_env["_#{prog_name}_COMPLETE"] = "#{shell}_source"
|
||||||
nil
|
nil
|
||||||
|
elsif shell_parameter_format == :clap
|
||||||
|
popen_read_env["COMPLETE"] = shell.to_s
|
||||||
|
nil
|
||||||
else
|
else
|
||||||
"#{shell_parameter_format}#{shell}"
|
"#{shell_parameter_format}#{shell}"
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user