homebrew-core/Formula/hcloud.rb

48 lines
1.7 KiB
Ruby

class Hcloud < Formula
desc "Command-line interface for Hetzner Cloud"
homepage "https://github.com/hetznercloud/cli"
url "https://github.com/hetznercloud/cli/archive/v1.16.0.tar.gz"
sha256 "eceaf25868706751392afc8cd1bef58a374f49437911335924ef1a27845f5a9a"
bottle do
cellar :any_skip_relocation
sha256 "e0ba553e5d832bfa5819bf3ec4f99b1bbd129bf5f2078b92ef1892b4c27eaee4" => :catalina
sha256 "fdad903f38805fc34817dc8b5b7b30aad44457ebff1b86694b568c44b7c9a24d" => :mojave
sha256 "89e1b9c0681aa0af543d501d17e009cd7f68513263e7bac687642b5b601af5e5" => :high_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