Module: Commands Private
- Defined in:
- Library/Homebrew/commands.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Helper functions for commands.
Constant Summary collapse
- HOMEBREW_CMD_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
(HOMEBREW_LIBRARY_PATH/"cmd").freeze
- HOMEBREW_DEV_CMD_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
(HOMEBREW_LIBRARY_PATH/"dev-cmd").freeze
- HOMEBREW_INTERNAL_COMMAND_ALIASES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ "ls" => "list", "homepage" => "home", "-S" => "search", "up" => "update", "ln" => "link", "instal" => "install", # gem does the same "uninstal" => "uninstall", "rm" => "uninstall", "remove" => "uninstall", "configure" => "diy", "abv" => "info", "dr" => "doctor", "--repo" => "--repository", "environment" => "--env", "--config" => "config", "-v" => "--version", "tc" => "typecheck", }.freeze
Class Method Summary collapse
- .args_method_name(cmd_path) ⇒ Object private
- .basename_without_extension(path) ⇒ Object private
- .cask_commands(aliases: false) ⇒ Object private
- .cask_external_commands ⇒ Object private
- .cask_internal_command_aliases ⇒ Object private
- .cask_internal_commands ⇒ Object private
- .commands(aliases: false) ⇒ Object private
- .external_cmd_path(cmd) ⇒ Object private
- .external_commands ⇒ Object private
-
.external_ruby_cmd_path(cmd) ⇒ Object
private
Ruby commands which are run by being
require
d. -
.external_ruby_v2_cmd_path(cmd) ⇒ Object
private
Ruby commands which can be
require
d without being run. - .find_commands(path) ⇒ Object private
- .find_internal_commands(path) ⇒ Object private
- .internal_cmd_path(cmd) ⇒ Object private
- .internal_commands ⇒ Object private
- .internal_commands_aliases ⇒ Object private
- .internal_commands_paths ⇒ Object private
- .internal_dev_cmd_path(cmd) ⇒ Object private
- .internal_developer_commands ⇒ Object private
- .internal_developer_commands_paths ⇒ Object private
- .method_name(cmd) ⇒ Object private
- .official_external_commands_paths(quiet:) ⇒ Object private
- .path(cmd) ⇒ Object private
- .rebuild_commands_completion_list ⇒ Object private
- .rebuild_internal_commands_completion_list ⇒ Object private
- .valid_internal_cmd?(cmd) ⇒ Boolean private
- .valid_internal_dev_cmd?(cmd) ⇒ Boolean private
Class Method Details
.args_method_name(cmd_path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 52 53 |
# File 'Library/Homebrew/commands.rb', line 49 def args_method_name(cmd_path) cmd_path_basename = basename_without_extension(cmd_path) cmd_method_prefix = method_name(cmd_path_basename) "#{cmd_method_prefix}_args".to_sym end |
.basename_without_extension(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
173 174 175 |
# File 'Library/Homebrew/commands.rb', line 173 def basename_without_extension(path) path.basename(path.extname) end |
.cask_commands(aliases: false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
145 146 147 148 149 150 |
# File 'Library/Homebrew/commands.rb', line 145 def cask_commands(aliases: false) cmds = cask_internal_commands cmds += cask_internal_command_aliases if aliases cmds += cask_external_commands cmds end |
.cask_external_commands ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'Library/Homebrew/commands.rb', line 160 def cask_external_commands PATH.new(Tap.cmd_directories, ENV["HOMEBREW_PATH"]).flat_map do |search_path| find_commands(search_path).map do |possible_command| path = possible_command.to_path command_name = path.match(/brewcask-(.*)\.rb/) { |data| data[1].delete_suffix(".rb") } if command_name.blank? && possible_command.executable? command_name = path.match(/brewcask-(.*)/) { |data| data[1] } end command_name end.compact end end |
.cask_internal_command_aliases ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
156 157 158 |
# File 'Library/Homebrew/commands.rb', line 156 def cask_internal_command_aliases Cask::Cmd.aliases.keys end |
.cask_internal_commands ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
152 153 154 |
# File 'Library/Homebrew/commands.rb', line 152 def cask_internal_commands Cask::Cmd.commands end |
.commands(aliases: false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
94 95 96 97 98 99 100 101 |
# File 'Library/Homebrew/commands.rb', line 94 def commands(aliases: false) cmds = internal_commands cmds += internal_developer_commands cmds += external_commands cmds += internal_commands_aliases if aliases cmds += cask_commands(aliases: aliases).map { |cmd| "cask #{cmd}" } cmds.sort end |
.external_cmd_path(cmd) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
80 81 82 |
# File 'Library/Homebrew/commands.rb', line 80 def external_cmd_path(cmd) which("brew-#{cmd}", PATH.new(ENV["PATH"]).append(Tap.cmd_directories)) end |
.external_commands ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
136 137 138 139 140 141 142 143 |
# File 'Library/Homebrew/commands.rb', line 136 def external_commands Tap.cmd_directories.flat_map do |path| find_commands(path).select(&:executable?) .map(&method(:basename_without_extension)) .map { |p| p.to_s.delete_prefix("brew-").strip } end.map(&:to_s) .sort end |
.external_ruby_cmd_path(cmd) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Ruby commands which are run by being require
d.
76 77 78 |
# File 'Library/Homebrew/commands.rb', line 76 def external_ruby_cmd_path(cmd) which("brew-#{cmd}.rb", PATH.new(ENV["PATH"]).append(Tap.cmd_directories)) end |
.external_ruby_v2_cmd_path(cmd) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Ruby commands which can be require
d without being run.
70 71 72 73 |
# File 'Library/Homebrew/commands.rb', line 70 def external_ruby_v2_cmd_path(cmd) path = which("#{cmd}.rb", Tap.cmd_directories) path if require?(path) end |
.find_commands(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
177 178 179 180 181 |
# File 'Library/Homebrew/commands.rb', line 177 def find_commands(path) Pathname.glob("#{path}/*") .select(&:file?) .sort end |
.find_internal_commands(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
131 132 133 134 |
# File 'Library/Homebrew/commands.rb', line 131 def find_internal_commands(path) find_commands(path).map(&:basename) .map(&method(:basename_without_extension)) end |
.internal_cmd_path(cmd) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 56 57 58 59 60 |
# File 'Library/Homebrew/commands.rb', line 55 def internal_cmd_path(cmd) [ HOMEBREW_CMD_PATH/"#{cmd}.rb", HOMEBREW_CMD_PATH/"#{cmd}.sh", ].find(&:exist?) end |
.internal_commands ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
119 120 121 |
# File 'Library/Homebrew/commands.rb', line 119 def internal_commands find_internal_commands(HOMEBREW_CMD_PATH).map(&:to_s) end |
.internal_commands_aliases ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
127 128 129 |
# File 'Library/Homebrew/commands.rb', line 127 def internal_commands_aliases HOMEBREW_INTERNAL_COMMAND_ALIASES.keys end |
.internal_commands_paths ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
103 104 105 |
# File 'Library/Homebrew/commands.rb', line 103 def internal_commands_paths find_commands HOMEBREW_CMD_PATH end |
.internal_dev_cmd_path(cmd) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 65 66 67 |
# File 'Library/Homebrew/commands.rb', line 62 def internal_dev_cmd_path(cmd) [ HOMEBREW_DEV_CMD_PATH/"#{cmd}.rb", HOMEBREW_DEV_CMD_PATH/"#{cmd}.sh", ].find(&:exist?) end |
.internal_developer_commands ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
123 124 125 |
# File 'Library/Homebrew/commands.rb', line 123 def internal_developer_commands find_internal_commands(HOMEBREW_DEV_CMD_PATH).map(&:to_s) end |
.internal_developer_commands_paths ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
107 108 109 |
# File 'Library/Homebrew/commands.rb', line 107 def internal_developer_commands_paths find_commands HOMEBREW_DEV_CMD_PATH end |
.method_name(cmd) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 45 46 47 |
# File 'Library/Homebrew/commands.rb', line 42 def method_name(cmd) cmd.to_s .tr("-", "_") .downcase .to_sym end |
.official_external_commands_paths(quiet:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
111 112 113 114 115 116 117 |
# File 'Library/Homebrew/commands.rb', line 111 def official_external_commands_paths(quiet:) %w[bundle services test-bot].map do |cmd| tap = Tap.fetch("Homebrew/#{cmd}") tap.install(quiet: quiet) unless tap.installed? external_ruby_v2_cmd_path(cmd) end end |
.path(cmd) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
84 85 86 87 88 89 90 91 92 |
# File 'Library/Homebrew/commands.rb', line 84 def path(cmd) internal_cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd) path ||= internal_cmd_path(internal_cmd) path ||= internal_dev_cmd_path(internal_cmd) path ||= external_ruby_v2_cmd_path(cmd) path ||= external_ruby_cmd_path(cmd) path ||= external_cmd_path(cmd) path end |
.rebuild_commands_completion_list ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
190 191 192 193 194 195 196 |
# File 'Library/Homebrew/commands.rb', line 190 def rebuild_commands_completion_list # Ensure that the cache exists so we can build the commands list HOMEBREW_CACHE.mkpath file = HOMEBREW_CACHE/"all_commands_list.txt" file.atomic_write("#{commands(aliases: true).sort.join("\n")}\n") end |
.rebuild_internal_commands_completion_list ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
183 184 185 186 187 188 |
# File 'Library/Homebrew/commands.rb', line 183 def rebuild_internal_commands_completion_list cmds = internal_commands + internal_developer_commands + internal_commands_aliases file = HOMEBREW_REPOSITORY/"completions/internal_commands_list.txt" file.atomic_write("#{cmds.sort.join("\n")}\n") end |
.valid_internal_cmd?(cmd) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 |
# File 'Library/Homebrew/commands.rb', line 34 def valid_internal_cmd?(cmd) require?(HOMEBREW_CMD_PATH/cmd) end |
.valid_internal_dev_cmd?(cmd) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 |
# File 'Library/Homebrew/commands.rb', line 38 def valid_internal_dev_cmd?(cmd) require?(HOMEBREW_DEV_CMD_PATH/cmd) end |