Class: Cask::Cmd Private
- Inherits:
-
Object
- Object
- Cask::Cmd
- Includes:
- Context
- Defined in:
- Library/Homebrew/cask/cmd.rb,
Library/Homebrew/cask/cmd/cat.rb,
Library/Homebrew/cask/cmd/zap.rb,
Library/Homebrew/cask/cmd/edit.rb,
Library/Homebrew/cask/cmd/help.rb,
Library/Homebrew/cask/cmd/home.rb,
Library/Homebrew/cask/cmd/info.rb,
Library/Homebrew/cask/cmd/list.rb,
Library/Homebrew/cask/cmd/audit.rb,
Library/Homebrew/cask/cmd/fetch.rb,
Library/Homebrew/cask/cmd/style.rb,
Library/Homebrew/cask/cmd/create.rb,
Library/Homebrew/cask/cmd/doctor.rb,
Library/Homebrew/cask/cmd/--cache.rb,
Library/Homebrew/cask/cmd/install.rb,
Library/Homebrew/cask/cmd/upgrade.rb,
Library/Homebrew/cask/cmd/outdated.rb,
Library/Homebrew/cask/cmd/reinstall.rb,
Library/Homebrew/cask/cmd/uninstall.rb,
Library/Homebrew/cask/cmd/internal_help.rb,
Library/Homebrew/cask/cmd/internal_stanza.rb,
Library/Homebrew/cask/cmd/abstract_command.rb,
Library/Homebrew/cask/cmd/abstract_internal_command.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Implementation of the brew cask
command-line interface.
Defined Under Namespace
Classes: AbstractCommand, AbstractInternalCommand, Audit, Cache, Cat, Create, Doctor, Edit, ExternalCommand, ExternalRubyCommand, Fetch, Help, Home, Info, Install, InternalHelp, InternalStanza, List, NullCommand, Outdated, Reinstall, Style, Uninstall, UnknownSubcommand, Upgrade, Zap
Constant Summary collapse
- 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", "instal" => "install", # gem does the same "uninstal" => "uninstall", "rm" => "uninstall", "remove" => "uninstall", "abv" => "info", "dr" => "doctor", }.freeze
- DEPRECATED_COMMANDS =
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.
{ Cmd::Cache => "brew --cache --cask", Cmd::Doctor => "brew doctor --verbose", Cmd::Home => "brew home", Cmd::List => "brew list --cask", Cmd::Outdated => "brew outdated --cask", Cmd::Reinstall => "brew reinstall", Cmd::Upgrade => "brew upgrade --cask", }.freeze
Class Method Summary collapse
- .aliases ⇒ Object private
- .command_classes ⇒ Object private
- .commands ⇒ Object private
- .description ⇒ Object private
- .lookup_command(command_name) ⇒ Object private
- .parser(&block) ⇒ Object private
- .run(*args) ⇒ Object private
Instance Method Summary collapse
- #detect_external_command(*args) ⇒ Object private
- #detect_internal_command(*args) ⇒ Object private
- #find_external_command(command) ⇒ Object private
-
#initialize(*args) ⇒ Cmd
constructor
private
A new instance of Cmd.
- #run ⇒ Object private
Methods included from Context
current, current=, #debug?, #quiet?, #verbose?, #with_context
Constructor Details
#initialize(*args) ⇒ Cmd
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.
Returns a new instance of Cmd.
124 125 126 |
# File 'Library/Homebrew/cask/cmd.rb', line 124 def initialize(*args) @argv = args end |
Class Method Details
.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.
116 117 118 |
# File 'Library/Homebrew/cask/cmd.rb', line 116 def self.aliases ALIASES end |
.command_classes ⇒ 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.
99 100 101 102 103 104 |
# File 'Library/Homebrew/cask/cmd.rb', line 99 def self.command_classes @command_classes ||= constants.map(&method(:const_get)) .select { |klass| klass.is_a?(Class) && klass < AbstractCommand } .reject(&:abstract?) .sort_by(&:command_name) end |
.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.
106 107 108 |
# File 'Library/Homebrew/cask/cmd.rb', line 106 def self.commands @commands ||= command_classes.map(&:command_name) end |
.description ⇒ 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.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'Library/Homebrew/cask/cmd.rb', line 64 def self.description max_command_length = Cmd.commands.map(&:length).max command_lines = Cmd.command_classes .select(&:visible?) .map do |klass| " - #{"`#{klass.command_name}`".ljust(max_command_length + 2)} #{klass.short_description}\n" end <<~EOS Homebrew Cask provides a friendly CLI workflow for the administration of macOS applications distributed as binaries. Commands: #{command_lines.join} See also: `man brew` EOS end |
.lookup_command(command_name) ⇒ 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.
110 111 112 113 114 |
# File 'Library/Homebrew/cask/cmd.rb', line 110 def self.lookup_command(command_name) @lookup ||= Hash[commands.zip(command_classes)] command_name = ALIASES.fetch(command_name, command_name) @lookup.fetch(command_name, nil) end |
.parser(&block) ⇒ 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.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'Library/Homebrew/cask/cmd.rb', line 83 def self.parser(&block) Homebrew::CLI::Parser.new do if block_given? instance_eval(&block) else <<~EOS `cask` <command> [<options>] [<cask>] #{Cmd.description} EOS end end end |
.run(*args) ⇒ 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.
120 121 122 |
# File 'Library/Homebrew/cask/cmd.rb', line 120 def self.run(*args) new(*args).run end |
Instance Method Details
#detect_external_command(*args) ⇒ 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 159 160 161 162 163 164 165 166 167 |
# File 'Library/Homebrew/cask/cmd.rb', line 156 def detect_external_command(*args) args.each_with_index do |arg, i| if command = find_external_command(arg) args.delete_at(i) return [command, args] elsif !arg.start_with?("-") break end end nil end |
#detect_internal_command(*args) ⇒ 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.
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'Library/Homebrew/cask/cmd.rb', line 143 def detect_internal_command(*args) args.each_with_index do |arg, i| if command = self.class.lookup_command(arg) args.delete_at(i) return [command, args] elsif !arg.start_with?("-") break end end nil end |
#find_external_command(command) ⇒ 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.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'Library/Homebrew/cask/cmd.rb', line 128 def find_external_command(command) @tap_cmd_directories ||= Tap.cmd_directories @path ||= PATH.new(@tap_cmd_directories, ENV["HOMEBREW_PATH"]) external_ruby_cmd = @tap_cmd_directories.map { |d| d/"brewcask-#{command}.rb" } .find(&:file?) external_ruby_cmd ||= which("brewcask-#{command}.rb", @path) if external_ruby_cmd ExternalRubyCommand.new(command, external_ruby_cmd) elsif external_command = which("brewcask-#{command}", @path) ExternalCommand.new(external_command) end end |
#run ⇒ 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.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'Library/Homebrew/cask/cmd.rb', line 169 def run argv = @argv args = self.class.parser.parse(argv, ignore_invalid_options: true) Tap.default_cask_tap.install unless Tap.default_cask_tap.installed? command, argv = detect_internal_command(*argv) || detect_external_command(*argv) || [args.remaining.empty? ? NullCommand : UnknownSubcommand.new(args.remaining.first), argv] if (replacement = DEPRECATED_COMMANDS[command]) odeprecated "brew cask #{command.command_name}", replacement end if args.help? puts command.help else command.run(*argv) end rescue CaskError, MethodDeprecatedError, ArgumentError => e onoe e. $stderr.puts e.backtrace if args.debug? exit 1 end |