homebrew-core/Formula/hcloud.rb

49 lines
1.8 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.19.0.tar.gz"
sha256 "f9223be383ddfeaefa90bfab756250248ba8a5a8810b0b0bb96560840a5e9ad4"
license "MIT"
bottle do
cellar :any_skip_relocation
sha256 "c62d55746d288a55ca788ef2fc67e204ba8b60b10e728bfea7261a45e855069f" => :catalina
sha256 "a8ff9bf17a674e294656a50f971f89b384ea962b3b9df8ecf4d75e54b2e7fd47" => :mojave
sha256 "23bfc988fdd87f5a98c99ff2160cea5c057b8d779b3ad3f0bf14e0bf42de21b9" => :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.safe_popen_read("#{bin}/hcloud", "completion", "bash")
(bash_completion/"hcloud").write output
output = Utils.safe_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