class IronFunctions < Formula
  desc "Go version of the IronFunctions command-line tools"
  homepage "https://github.com/iron-io/functions"
  url "https://github.com/iron-io/functions/archive/0.2.68.tar.gz"
  sha256 "81700463d0ded0966cc69261112eba9d479c31dbd4006e38243ef8f818a70f69"

  bottle do
    cellar :any_skip_relocation
    sha256 "cd5e796945b3bfae759d28ff32b64ef4a41c2442241dd49ec1da14ad42063a5d" => :high_sierra
    sha256 "6ca9ad0df6b6d17ddfe0b357ed0af5cace0d23575a4336615b2381812138fd95" => :sierra
    sha256 "575c789703ce06c4d2c70000e170729665419ac3e5d9cf4891487cdfaaaf3289" => :el_capitan
    sha256 "8ba15af67cb6738ec30b9699152f79a7f6027c1dd79e4d492489670b80d1f217" => :x86_64_linux
  end

  depends_on "dep" => :build
  depends_on "go" => :build

  def install
    ENV["GOPATH"] = buildpath
    dir = buildpath/"src/github.com/iron-io/functions"
    dir.install Dir["*"]
    cd dir/"fn" do
      system "make", "dep"
      system "go", "build", "-o", bin/"fn"
      prefix.install_metafiles
    end
  end

  test do
    expected = <<~EOS
      runtime: go
      func.yaml created.
    EOS
    output = shell_output("#{bin}/fn init --runtime go user/some 2>&1")
    assert_equal expected, output
  end
end
