class Hcloud < Formula desc "Command-line interface for Hetzner Cloud" homepage "https://github.com/hetznercloud/cli" url "https://github.com/hetznercloud/cli/archive/v1.9.1.tar.gz" sha256 "9e74390b075ec4b935cbe5cef415e5280c53f7026973787ee69006cd5fcc9170" bottle do cellar :any_skip_relocation sha256 "9b068b76253fae731e35c281b6bbc120b066cd683860a350a8633669a9dee721" => :mojave sha256 "5f738e44747709972ad3e585dddd3d39bac7bd2293ac916403ca1c250b67238c" => :high_sierra sha256 "5a69543beb31f4b0d431241e64b42f47b3e741f77db4d3f958bac3f0be30d3fb" => :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