Port Homebrew::Cmd::Home

This commit is contained in:
Douglas Eichelberger 2024-03-29 18:34:33 -07:00
parent d0c1af4f9e
commit 74218c0483
3 changed files with 41 additions and 40 deletions

View File

@ -1,15 +1,13 @@
# typed: true
# frozen_string_literal: true
require "cli/parser"
require "abstract_command"
require "formula"
module Homebrew
module_function
sig { returns(CLI::Parser) }
def home_args
Homebrew::CLI::Parser.new do
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.
@ -23,12 +21,9 @@ module Homebrew
named_args [:formula, :cask]
end
end
sig { void }
def home
args = home_args.parse
sig { override.void }
def run
if args.no_named?
exec_browser HOMEBREW_WWW
return
@ -51,4 +46,6 @@ module Homebrew
"Cask #{formula_or_cask.token}"
end
end
end
end
end

View File

@ -1,8 +1,11 @@
# frozen_string_literal: true
require "cmd/help"
require "cmd/shared_examples/args_parse"
RSpec.describe Homebrew::Cmd::HelpCmd, :integration_test do
it_behaves_like "parseable arguments"
describe "help" do
it "prints help for a documented Ruby command" do
expect { brew "help", "cat" }

View File

@ -1,8 +1,9 @@
# frozen_string_literal: true
require "cmd/home"
require "cmd/shared_examples/args_parse"
RSpec.describe "brew home" do
RSpec.describe Homebrew::Cmd::Home do
let(:testballhome_homepage) do
Formula["testballhome"].homepage
end