Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homebrew #17

Open
awendland opened this issue Aug 17, 2020 · 3 comments
Open

Homebrew #17

awendland opened this issue Aug 17, 2020 · 3 comments

Comments

@awendland
Copy link

First off, thank you so much for creating this tool! It's been a super useful introduction to my CLI toolset that has made working with huge numbers of files so much easier.

I was hoping to make this tool installable via Homebrew, macOS's unofficial package manager. There are two ways to create a new entry in Homebrew (as far as I'm aware):

  1. Submit a Formula to homebrew-core that compiles brename from source for macOS. See
    • Pro: This would allow users to run brew install brename.
    • Con: This requires vendoring to be introduced to the project according to the brew audit tool: C: 19: col 7: Do not use `go get`. Please ask upstream to implement Go vendoring
    • Con: This cannot leverage the assets already built and published on GitHub releases.
  2. Create a Tap that users can install from using, e.g., brew install shenwei356/tap/brename (see how croc, another golang project, handles it):
    • Pro: This directly uses the assets stored GitHub releases.
    • Pro: This mandates no changes to the current repository.
    • Con: This usually mandates creating a new repository. However, an approach like pup.rb can be taken where the file is committed directly to this repository and then the user runs a command like brew install https://raw.githubusercontent.com/shenwei356/brename/master/brename.rb which is more bulky).
    • Other: GoReleaser can be used to autogenerate these Formula.

I've made an attempt to author a Formula for both approaches:

homebrew-core Formula

class Brename < Formula
  desc "Safely batch rename files/directories via regular expression"
  homepage "https://github.com/shenwei356/brename"
  url "https://github.com/shenwei356/brename.git",
      tag:      "v2.11.0",
      revision: "c945c33a689b4e79385826db9c828bbf77644e14"
  license "MIT"
  head "https://github.com/shenwei356/brename.git"

  depends_on "go" => :build
  depends_on "gox" => :build

  def install
    ENV["GOPATH"] = buildpath
    dir = buildpath/"src/github.com/shenwei356/brename"
    dir.install buildpath.children

    cd dir do
      system "go", "get", "-v"
      system "gox", "-arch", "amd64", "-os", "darwin", "./..."
      bin.install "brename_darwin_amd64" => "brename"
    end

    prefix.install_metafiles dir
  end

  test do
    # brename normally outputs status information to stderr but shell_output only captures
    # stdout so it must be redirected
    assert_match "checking: \[ ok \]",
      shell_output("#{bin}/brename -p 'zip' -r 'zippy' -d #{test_fixtures("cask")} 2>&1")
  end
end

Tap Formula

class Brename < Formula
  version "2.11.0"
  desc "Safely batch rename files/directories via regular expression"
  homepage "https://github.com/shenwei356/brename"
  license "MIT"
  bottle :unneeded

  if OS.mac?
    if Hardware::CPU.is_64_bit?
      url "https://github.com/shenwei356/brename/releases/download/v2.11.0/brename_darwin_amd64.tar.gz"
      sha256 "7f0094cbaed1154737c716db737404371e7f8e323b09b729455547cd0c75c857"
    else
      url "https://github.com/shenwei356/brename/releases/download/v2.11.0/brename_darwin_386.tar.gz"
      sha256 "1c912a8528247a03a08e44c84974f53c923f3ffa1af4588e4399fa9d3361e060"
    end
  elsif OS.linux?
    if Hardware::CPU.is_64_bit?
      url "https://github.com/shenwei356/brename/releases/download/v2.11.0/brename_linux_amd64.tar.gz"
      sha256 "baf95821def8db827f57995fe2716cac21eddc8215d20c14dfddeb241f03648c"
    else
      url "https://github.com/shenwei356/brename/releases/download/v2.11.0/brename_linux_386.tar.gz"
      sha256 "02606e709bba976d4f80ef2134733e41fc40700b29187330c61dd70108f66d83"
    end
  end

  def install
    bin.install "brename"
  end

  test do
    # brename normally outputs status information to stderr but shell_output only captures
    # stdout so it must be redirected
    assert_match "checking: \[ ok \]",
      shell_output("#{bin}/brename -p 'zip' -r 'zippy' -d #{test_fixtures("cask")} 2>&1")
  end
end
@shenwei356
Copy link
Owner

Nice! Thank you!

I'm not familiar with homebrew, I submit my other tools written in go to homebrew-bio similar with the second method, but they only accept bioinformatics-related tools.

I've tried to submit csvtk to homebrew-core but failed.

@awendland
Copy link
Author

This is my first foray into homebrew, so it sounds like your experience might be stronger in this regard. If homebrew core is proving difficult, would you be open to hosting something like the what the croc maintainer does? He (schollz) hosts a file Formula/croc.rb in a repo called schollz/homebrew-tap. This allows users to run brew install schollz/tap/croc. I think it would be more trustworthy for you to host a brename Formula (the Tap Formula I posted in my original comment should work for the v2.11.0 release) than anyone else 🙂

@shenwei356
Copy link
Owner

Actually some kind guys helped to write those formulas. The https://github.com/schollz/homebrew-tap way looks easy and feasible, I'll try to put all my apps in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants