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

Support external commands beneath brew cask #2594

Merged
merged 1 commit into from
Jan 28, 2014
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,17 @@ line of an email. (See [CONTRIBUTING.md](CONTRIBUTING.md#commit-messages)).
A short but complete summary line helps the maintainers respond to your
pull request more quickly.

### External Commands

Advanced users may create their own external commands for homebrew-cask by
following conventions similar to external commands for git or Homebrew. An
external command may be any executable on your `$PATH` which follows the
form `brewcask-<command>`. (So long as `<command>` does not conflict with
an existing command verb.) The command will be invoked by `exec` and passed
any unprocessed arguments from the original command-line. An external
command may also be implemented as an executable Ruby file, on your `$PATH`,
which follows the form `brewcask-<command>.rb`. The Ruby file will be
`required` and will have full access to the Ruby environments of both
homebrew-cask and Homebrew.

# <3 THANK YOU! <3
32 changes: 24 additions & 8 deletions lib/cask/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,32 @@ def self.commands
Cask::CLI.constants - ["NullCommand"]
end

def self.lookup_command(command)
if command && Cask::CLI.const_defined?(command.capitalize)
Cask::CLI.const_get(command.capitalize)
def self.lookup_command(command_string)
if command_string && Cask::CLI.const_defined?(command_string.capitalize)
Cask::CLI.const_get(command_string.capitalize)
else
Cask::CLI::NullCommand.new(command)
command_string
end
end

def self.run_command(command, *rest)
if command.respond_to?(:run)
command.run(*rest)
elsif which "brewcask-#{command}"
exec "brewcask-#{command}", *ARGV[1..-1]
elsif require? which("brewcask-#{command}.rb").to_s
exit 0
else
Cask::CLI::NullCommand.new(command).run
end
end

def self.process(arguments)
command, *rest = *arguments
command_string, *rest = *arguments
rest = process_options(rest)
Cask.init
lookup_command(command).run(*rest)
command = lookup_command(command_string)
run_command(command, *rest)
rescue CaskAlreadyInstalledError => e
opoo e
$stderr.puts e.backtrace if @debug
Expand Down Expand Up @@ -151,8 +164,11 @@ def help
''
end

def _help_for(command)
Cask::CLI.lookup_command(command).help
def _help_for(command_string)
command = Cask::CLI.lookup_command(command_string)
if command.respond_to?(:help)
command.help
end
end
end
end