From 841cfd9fdce527a64a11da11be8625a4c55746ee Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Mon, 1 Apr 2024 11:42:17 -0700 Subject: [PATCH] Port Homebrew::Cmd::Tap --- Library/Homebrew/cmd/tap.rb | 130 +++++++++++++------------- Library/Homebrew/test/cmd/tap_spec.rb | 3 +- 2 files changed, 66 insertions(+), 67 deletions(-) diff --git a/Library/Homebrew/cmd/tap.rb b/Library/Homebrew/cmd/tap.rb index 86005e7cb5..68fd8d1937 100644 --- a/Library/Homebrew/cmd/tap.rb +++ b/Library/Homebrew/cmd/tap.rb @@ -1,77 +1,75 @@ -# typed: true +# typed: strict # frozen_string_literal: true -require "cli/parser" +require "abstract_command" module Homebrew - module_function + module Cmd + class TapCmd < AbstractCommand + cmd_args do + usage_banner "`tap` [] [`/`] []" + description <<~EOS + Tap a formula repository. + If no arguments are provided, list all installed taps. - sig { returns(CLI::Parser) } - def tap_args - Homebrew::CLI::Parser.new do - usage_banner "`tap` [] [`/`] []" - description <<~EOS - Tap a formula repository. - If no arguments are provided, list all installed taps. + With unspecified, tap a formula repository from GitHub using HTTPS. + Since so many taps are hosted on GitHub, this command is a shortcut for + `brew tap` `/` `https://github.com/``/homebrew-`. - With unspecified, tap a formula repository from GitHub using HTTPS. - Since so many taps are hosted on GitHub, this command is a shortcut for - `brew tap` `/` `https://github.com/``/homebrew-`. + With specified, tap a formula repository from anywhere, using + any transport protocol that `git`(1) handles. The one-argument form of `tap` + simplifies but also limits. This two-argument command makes no + assumptions, so taps can be cloned from places other than GitHub and + using protocols other than HTTPS, e.g. SSH, git, HTTP, FTP(S), rsync. + EOS + switch "--full", + description: "Convert a shallow clone to a full clone without untapping. Taps are only cloned as " \ + "shallow clones if `--shallow` was originally passed.", + replacement: false, + disable: true + switch "--shallow", + description: "Fetch tap as a shallow clone rather than a full clone. Useful for continuous " \ + "integration.", + replacement: false, + disable: true + switch "--[no-]force-auto-update", + hidden: true + switch "--custom-remote", + description: "Install or change a tap with a custom remote. Useful for mirrors." + switch "--repair", + description: "Migrate tapped formulae from symlink-based to directory-based structure." + switch "--eval-all", + description: "Evaluate all the formulae, casks and aliases in the new tap to check validity. " \ + "Implied if `HOMEBREW_EVAL_ALL` is set." + switch "--force", + description: "Force install core taps even under API mode." - With specified, tap a formula repository from anywhere, using - any transport protocol that `git`(1) handles. The one-argument form of `tap` - simplifies but also limits. This two-argument command makes no - assumptions, so taps can be cloned from places other than GitHub and - using protocols other than HTTPS, e.g. SSH, git, HTTP, FTP(S), rsync. - EOS - switch "--full", - description: "Convert a shallow clone to a full clone without untapping. Taps are only cloned as " \ - "shallow clones if `--shallow` was originally passed.", - replacement: false, - disable: true - switch "--shallow", - description: "Fetch tap as a shallow clone rather than a full clone. Useful for continuous integration.", - replacement: false, - disable: true - switch "--[no-]force-auto-update", - hidden: true - switch "--custom-remote", - description: "Install or change a tap with a custom remote. Useful for mirrors." - switch "--repair", - description: "Migrate tapped formulae from symlink-based to directory-based structure." - switch "--eval-all", - description: "Evaluate all the formulae, casks and aliases in the new tap to check validity. " \ - "Implied if `HOMEBREW_EVAL_ALL` is set." - switch "--force", - description: "Force install core taps even under API mode." - - named_args :tap, max: 2 - end - end - - sig { void } - def tap - args = tap_args.parse - - if args.repair? - Tap.installed.each do |tap| - tap.link_completions_and_manpages - tap.fix_remote_configuration + named_args :tap, max: 2 end - elsif args.no_named? - puts Tap.installed.sort_by(&:name) - else - tap = Tap.fetch(args.named.first) - begin - tap.install clone_target: args.named.second, - custom_remote: args.custom_remote?, - quiet: args.quiet?, - verify: args.eval_all? || Homebrew::EnvConfig.eval_all?, - force: args.force? - rescue TapRemoteMismatchError, TapNoCustomRemoteError => e - odie e - rescue TapAlreadyTappedError - nil + + sig { override.void } + def run + if args.repair? + Tap.installed.each do |tap| + tap.link_completions_and_manpages + tap.fix_remote_configuration + end + elsif args.no_named? + puts Tap.installed.sort_by(&:name) + else + tap = Tap.fetch(args.named.first) + begin + tap.install clone_target: args.named.second, + custom_remote: args.custom_remote?, + quiet: args.quiet?, + verify: args.eval_all? || Homebrew::EnvConfig.eval_all?, + force: args.force? + rescue TapRemoteMismatchError, TapNoCustomRemoteError => e + odie e + rescue TapAlreadyTappedError + nil + end + end end end end diff --git a/Library/Homebrew/test/cmd/tap_spec.rb b/Library/Homebrew/test/cmd/tap_spec.rb index 36d018eeab..5d36439bfb 100644 --- a/Library/Homebrew/test/cmd/tap_spec.rb +++ b/Library/Homebrew/test/cmd/tap_spec.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true require "cmd/shared_examples/args_parse" +require "cmd/tap" -RSpec.describe "brew tap" do +RSpec.describe Homebrew::Cmd::TapCmd do it_behaves_like "parseable arguments" it "taps a given Tap", :integration_test do