Skip to content
Snippets Groups Projects
Unverified Commit 86f4362d authored by Mike McQuaid's avatar Mike McQuaid Committed by GitHub
Browse files

Merge pull request #8805 from hyuraku/cask_github_info

show cask info on browser
parents 6e5b3f57 137d3329
No related branches found
No related tags found
No related merge requests found
......@@ -18,14 +18,38 @@ module Cask
def self.parser
super do
flag "--json=",
description: "Output information in JSON format."
flag "--json=",
description: "Output information in JSON format."
switch "--github",
description: "Open the GitHub source page for <Cask> in a browser. "
end
end
def github_info(cask)
sourcefile_path = cask.sourcefile_path
dir = cask.tap.path
path = sourcefile_path.relative_path_from(dir)
remote = cask.tap.remote
github_remote_path(remote, path)
end
def github_remote_path(remote, path)
if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$}
"https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/blob/HEAD/#{path}"
else
"#{remote}/#{path}"
end
end
def run
if args.json == "v1"
puts JSON.generate(casks.map(&:to_h))
elsif args.github?
raise CaskUnspecifiedError if args.no_named?
args.named.to_formulae_and_casks.map do |cask|
exec_browser(github_info(cask))
end
else
casks.each_with_index do |cask, i|
puts unless i.zero?
......
......@@ -86,7 +86,7 @@ module Homebrew
elsif args.github?
raise FormulaUnspecifiedError if args.no_named?
exec_browser(*args.named.to_formulae.map { |f| github_info(f) })
exec_browser(*args.named.to_formulae_and_casks.map { |f| github_info(f) })
else
print_info(args: args)
end
......@@ -148,7 +148,11 @@ module Homebrew
def github_info(f)
if f.tap
if remote = f.tap.remote
path = f.path.relative_path_from(f.tap.path)
path = if f.class.superclass == Formula
f.path.relative_path_from(f.tap.path)
elsif f.is_a?(Cask::Cask)
f.sourcefile_path.relative_path_from(f.tap.path)
end
github_remote_path(remote, path)
else
f.path
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment