diff --git a/Library/Homebrew/cmd/--repository.rb b/Library/Homebrew/cmd/--repository.rb deleted file mode 100644 index d3691290de..0000000000 --- a/Library/Homebrew/cmd/--repository.rb +++ /dev/null @@ -1,32 +0,0 @@ -# typed: strict -# frozen_string_literal: true - -require "abstract_command" - -module Homebrew - module Cmd - class Repository < AbstractCommand - sig { override.returns(String) } - def self.command_name = "--repository" - - cmd_args do - description <<~EOS - Display where Homebrew's Git repository is located. - - If `/` are provided, display where tap `/`'s directory is located. - EOS - - named_args :tap - end - - sig { override.void } - def run - if args.no_named? - puts HOMEBREW_REPOSITORY - else - puts args.named.to_taps.map(&:path) - end - end - end - end -end diff --git a/Library/Homebrew/cmd/--repository.sh b/Library/Homebrew/cmd/--repository.sh new file mode 100644 index 0000000000..90aad78969 --- /dev/null +++ b/Library/Homebrew/cmd/--repository.sh @@ -0,0 +1,44 @@ +#: * `--repository`, `--repo` [ ...] +#: +#: Display where Homebrew's Git repository is located. +#: +#: If `/` are provided, display where tap `/`'s directory is located. + +# HOMEBREW_REPOSITORY, HOMEBREW_LIBRARY are set by brew.sh +# shellcheck disable=SC2154 + +tap_path() { + local tap="$1" + local user + local repo + local part + + user="$(echo "${tap%%/*}" | tr '[:upper:]' '[:lower:]')" + repo="$(echo "${tap#*/}" | tr '[:upper:]' '[:lower:]')" + + for part in "${user}" "${repo}" + do + if [[ -z "${part}" || "${part}" == *"/"* ]] + then + odie "Invalid tap name: ${tap}" + fi + done + + repo="${repo#(home|linux)brew-}" + echo "${HOMEBREW_LIBRARY}/Taps/${user}/homebrew-${repo}" +} + +homebrew---repository() { + local tap + + if [[ "$#" -eq 0 ]] + then + echo "${HOMEBREW_REPOSITORY}" + return + fi + + for tap in "$@" + do + tap_path "${tap}" + done +} diff --git a/Library/Homebrew/test/cmd/--repository_spec.rb b/Library/Homebrew/test/cmd/--repository_spec.rb index 1fcc495044..711dbf8549 100644 --- a/Library/Homebrew/test/cmd/--repository_spec.rb +++ b/Library/Homebrew/test/cmd/--repository_spec.rb @@ -1,11 +1,6 @@ # frozen_string_literal: true -require "cmd/--repository" -require "cmd/shared_examples/args_parse" - -RSpec.describe Homebrew::Cmd::Repository do - it_behaves_like "parseable arguments" - +RSpec.describe "brew --repository", type: :system do it "prints Homebrew's repository", :integration_test do expect { brew_sh "--repository" } .to output("#{ENV.fetch("HOMEBREW_REPOSITORY")}\n").to_stdout @@ -14,8 +9,8 @@ RSpec.describe Homebrew::Cmd::Repository do end it "prints a Tap's repository", :integration_test do - expect { brew "--repository", "foo/bar" } - .to output("#{HOMEBREW_LIBRARY}/Taps/foo/homebrew-bar\n").to_stdout + expect { brew_sh "--repository", "foo/bar" } + .to output("#{ENV.fetch("HOMEBREW_LIBRARY")}/Taps/foo/homebrew-bar\n").to_stdout .and not_to_output.to_stderr .and be_a_success end