'homebrew install dependencies if unmet

I have a brew package setup through GitHub: diagnosticator

This is a simple ruby file (diagnosticator.rb) that points to the actual hosting repository: diagnosticator-mac and provides instructions on how to install files:

class Diagnosticator < Formula
  desc "Diagnosticator Mac OS homebrew package"
  homepage "https://diagnosticator.com"
  url "https://github.com/cccnrc/diagnosticator-mac/archive/refs/tags/v0.1.11.tar.gz"
  sha256 "f36987ce96c7be269da12b9dce8186c5245aef4046fe62173a145024b5e88b98"
  license "MIT"

  depends_on "docker"
  depends_on "docker-compose"
  depends_on "wget"
  depends_on "jq"

  def install
    bin.install "diagnosticator"
    bin.install "diagnosticator-mac.sh"
    bin.install Dir["files"]
    prefix.install "README.md"
  end
end

How can I tell brew to automatically install dependencies (docker, docker-compose, wget, and jq) if they are unmet in the machine that is installing diagnosticator?


If you want to try it:

brew install cccnrc/diagnosticator/diagnosticator


Solution 1:[1]

This might be something that you are looking for.

Setup the formula file as below

cat << EOF > ./formula/diagnosticator.rb
class Diagnosticator < Formula
  desc "Diagnosticator Mac OS homebrew package"
  homepage "https://diagnosticator.com"
  url "https://github.com/cccnrc/diagnosticator-mac/archive/refs/tags/v0.1.11.tar.gz"
  sha256 "f36987ce96c7be269da12b9dce8186c5245aef4046fe62173a145024b5e88b98"
  license "MIT"

  depends_on "docker"
  depends_on "docker-compose"
  depends_on "wget"
  depends_on "jq"

  def install
    bin.install "diagnosticator"
    bin.install "diagnosticator-mac.sh"
    bin.install Dir["files"]
    prefix.install "README.md"
  end
end
EOF

And then run brew info diagnosticator

$ brew info diagnosticator
diagnosticator: stable 0.1.11
Diagnosticator Mac OS homebrew package
https://diagnosticator.com
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/diagnosticator.rb
License: MIT
==> Dependencies
Required: docker ?, docker-compose ?, wget ?, jq ?

Let me know if that works.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 chenrui