class Hcloud < Formula desc "Command-line interface for Hetzner Cloud" homepage "https://github.com/hetznercloud/cli" url "https://github.com/hetznercloud/cli/archive/v1.10.0.tar.gz" sha256 "69366f84753e1c4bbd9312be3fade23a8888969feee39eafefbd581919dbada4" bottle do cellar :any_skip_relocation sha256 "f043ac2f3b8545feab56999d41c998cc8a90469c5f3db5a499f3b82d19258ba0" => :mojave sha256 "7a052a0266e1e793fc891d30862a5a868ced55313e131e0a8597c64e27df8282" => :high_sierra sha256 "e58763394a36c4e838669a6020fdc55d61c020f7a4a9643687fef346391b4c65" => :sierra end depends_on "go" => :build def install ENV["GOPATH"] = HOMEBREW_CACHE/"go_cache" (buildpath/"src/github.com/hetznercloud/cli").install buildpath.children cd "src/github.com/hetznercloud/cli" do ldflags = "-w -X github.com/hetznercloud/cli/cli.Version=v#{version}" system "go", "build", "-o", bin/"hcloud", "-ldflags", ldflags, "./cmd/hcloud" prefix.install_metafiles end output = Utils.popen_read("#{bin}/hcloud completion bash") (bash_completion/"hcloud").write output output = Utils.popen_read("#{bin}/hcloud completion zsh") (zsh_completion/"_hcloud").write output end test do config_path = testpath/".config/hcloud/cli.toml" ENV["HCLOUD_CONFIG"] = config_path assert_match "", shell_output("#{bin}/hcloud context active") config_path.write <<~EOS active_context = "test" [[contexts]] name = "test" token = "foobar" EOS assert_match "test", shell_output("#{bin}/hcloud context list") assert_match "test", shell_output("#{bin}/hcloud context active") assert_match "hcloud v#{version}", shell_output("#{bin}/hcloud version") end end