class GnuGetopt < Formula desc "Command-line option parsing utility" homepage "https://github.com/util-linux/util-linux" url "https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.42/util-linux-2.42.2.tar.gz" sha256 "e73fe91d9b536c6e3548132c1e327843b0bac3c94be9f158ce112eb989d25fc7" license "GPL-2.0-or-later" compatibility_version 1 livecheck do url "https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/" regex(/href=.*?util-linux[._-]v?(\d+(?:\.\d+)+)\.t/i) strategy :page_match do |page, regex| # Match versions from directories versions = page.scan(%r{href=["']?v?(\d+(?:\.\d+)+)/?["' >]}i) .flatten .uniq .sort_by { |v| Version.new(v) } next versions if versions.blank? # Check the highest version, falling back to the second-highest version # if no matching versions are found in the version directory (e.g., # upstream has created a version directory using a stable version format # but the version directory only contained unstable versions). dir_versions = [] versions[-2..].reverse_each do |version| # Fetch the page for the version directory dir_page = Homebrew::Livecheck::Strategy.page_content( URI.join(@url, "v#{version}/").to_s, ) next versions if dir_page[:content].blank? # Identify versions from files in the version directory dir_versions = dir_page[:content].scan(regex).flatten break unless dir_versions.empty? end dir_versions.presence || versions end end bottle do sha256 cellar: :any_skip_relocation, arm64_tahoe: "8686e5c9467fcf792109ed51bdc112a33440a76867813493ab06ec841b6e5670" sha256 cellar: :any_skip_relocation, arm64_sequoia: "cf63a74c9a13211492505f5e1ea63518fe3c2610ad3966560d3b0ed29d1bcfed" sha256 cellar: :any_skip_relocation, arm64_sonoma: "ed46a7f05b0d415f1c5d64d0fd65f1fed773758437e83a5379214ad053f1592b" sha256 cellar: :any_skip_relocation, sonoma: "dfe481ad58f986d3346be3a45dd67159d3c9fa198f3f007613b5511abd770da0" sha256 cellar: :any, arm64_linux: "13bf47751b729ca87dfb73c4a0c3be145c678610ab40914238e66a5f546d55d5" sha256 cellar: :any, x86_64_linux: "1f8d71983ef6e65de71b785fadbc1e8d6331fa0232317b279fd710541ee17c74" end keg_only :shadowed_by_macos, "macOS provides BSD getopt" on_linux do keg_only "it conflicts with util-linux" end # Fix macOS builds # https://github.com/util-linux/util-linux/pull/4173 patch do url "https://github.com/util-linux/util-linux/commit/d22edc2f100eb8dd83d3515758565cb73b0d2eed.patch?full_index=1" sha256 "2fb01154faa3fd8b0fce27eb88049ed9c8f839e706e412399c19c087f7f3b5e1" end def install system "./configure", "--disable-silent-rules", "--disable-liblastlog2", *std_configure_args system "make", "getopt", "misc-utils/getopt.1" bin.install "getopt" man1.install "misc-utils/getopt.1" bash_completion.install "bash-completion/getopt" doc.install "misc-utils/getopt-example.bash", "misc-utils/getopt-example.tcsh" end test do output = shell_output("#{bin}/getopt --longoptions foo --options ab:c test -b bar --foo baz") assert_equal " -b 'bar' --foo -- 'test' 'baz'\n", output # Check that getopt is enhanced assert_empty shell_output("#{bin}/getopt --test", 4) end end