2020-11-18 08:10:21 +01:00
|
|
|
# typed: true
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-03-29 18:34:33 -07:00
|
|
|
require "abstract_command"
|
2020-11-18 08:10:21 +01:00
|
|
|
require "formula"
|
2018-11-06 21:28:12 +05:30
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2024-03-29 18:34:33 -07:00
|
|
|
module Cmd
|
|
|
|
class Home < AbstractCommand
|
|
|
|
cmd_args do
|
|
|
|
description <<~EOS
|
|
|
|
Open a <formula> or <cask>'s homepage in a browser, or open
|
|
|
|
Homebrew's own homepage if no argument is provided.
|
|
|
|
EOS
|
|
|
|
switch "--formula", "--formulae",
|
|
|
|
description: "Treat all named arguments as formulae."
|
|
|
|
switch "--cask", "--casks",
|
|
|
|
description: "Treat all named arguments as casks."
|
|
|
|
|
|
|
|
conflicts "--formula", "--cask"
|
|
|
|
|
|
|
|
named_args [:formula, :cask]
|
|
|
|
end
|
|
|
|
|
|
|
|
sig { override.void }
|
|
|
|
def run
|
|
|
|
if args.no_named?
|
|
|
|
exec_browser HOMEBREW_WWW
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# to_formulae_and_casks is typed to possibly return Kegs (but won't without explicitly asking)
|
|
|
|
formulae_or_casks = T.cast(args.named.to_formulae_and_casks, T::Array[T.any(Formula, Cask::Cask)])
|
|
|
|
homepages = formulae_or_casks.map do |formula_or_cask|
|
|
|
|
puts "Opening homepage for #{name_of(formula_or_cask)}"
|
|
|
|
formula_or_cask.homepage
|
|
|
|
end
|
|
|
|
|
|
|
|
exec_browser(*T.unsafe(homepages))
|
|
|
|
end
|
|
|
|
|
|
|
|
def name_of(formula_or_cask)
|
|
|
|
if formula_or_cask.is_a? Formula
|
|
|
|
"Formula #{formula_or_cask.name}"
|
|
|
|
else
|
|
|
|
"Cask #{formula_or_cask.token}"
|
|
|
|
end
|
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|