Module: Utils::ShellCompletion Private
- Defined in:
- utils/shell_completion.rb
Overview
This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
Shared logic for generating shell completion scripts. Used by both Formula#generate_completions_from_executable and Cask::Artifact::GeneratedCompletion.
Class Method Summary collapse
- .completion_shell_parameter(format, shell, executable, env) ⇒ String, ... private
- .default_completion_shells(format) ⇒ Array<Symbol> private
- .generate_completion_output(commands, shell_parameter, env) ⇒ String private
Class Method Details
.completion_shell_parameter(format, shell, executable, env) ⇒ String, ...
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'utils/shell_completion.rb', line 27 def self.completion_shell_parameter(format, shell, executable, env) # Go's cobra and Rust's clap accept "powershell". shell_parameter = (shell == :pwsh) ? "powershell" : shell.to_s case format when nil shell_parameter when :arg "--shell=#{shell_parameter}" when :clap env["COMPLETE"] = shell_parameter nil when :click prog_name = File.basename(executable).upcase.tr("-", "_") env["_#{prog_name}_COMPLETE"] = "#{shell_parameter}_source" nil when :cobra ["completion", shell_parameter] when :flag "--#{shell_parameter}" when :none nil when :typer env["_TYPER_COMPLETE_TEST_DISABLE_SHELL_DETECTION"] = "1" ["--show-completion", shell_parameter] else "#{format}#{shell}" end end |
.default_completion_shells(format) ⇒ Array<Symbol>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
10 11 12 13 14 15 16 17 |
# File 'utils/shell_completion.rb', line 10 def self.default_completion_shells(format) case format when :cobra, :typer [:bash, :zsh, :fish, :pwsh] else [:bash, :zsh, :fish] end end |
.generate_completion_output(commands, shell_parameter, env) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
64 65 66 67 68 69 |
# File 'utils/shell_completion.rb', line 64 def self.generate_completion_output(commands, shell_parameter, env) args = T.let(commands + Array(shell_parameter), T::Array[T.any(Pathname, String)]) = T.let({}, T::Hash[Symbol, Symbol]) [:err] = :err unless ENV["HOMEBREW_STDERR"] Utils.safe_popen_read(env, *args, **) end |