piranha / goreplace

command line tool for search and replace
ISC License
185 stars 14 forks source link

Add `go.mod` #38

Closed a-h closed 4 years ago

a-h commented 4 years ago

Hi, great tool, thanks!

This doesn't do anything new, just adds the Go module files.

I'm not sure if this is particularly an improvement aside from pinning versions of the dependencies and enabling Github Dependabot to analyse the project, but it makes it easier for me to package the app using Nix, which is why I have a fork (Nix expression below, in case anyone is looking).

{ lib, buildGoModule, fetchFromGitHub }:

buildGoModule rec {
  pname = "goreplace";
  version = "2.6";

  src = fetchFromGitHub {
    owner = "a-h";
    repo = "goreplace";
    rev = "653683efc0a6e08da1168c6599216ee81236f95b";
    sha256 = "1ia0yns20q8b9yhmpyavzbb2zvyh960i5v1hbprsb3pqb76h89cg";
  };

  vendorSha256 = "0njcdk1yns5jp9zklpw63r6xvdlz96l1ba66hhngczr3017g66jf";

  meta = with lib; {
    description = "Replace in files.";
    homepage = https://github.com/piranha/goreplace;
    license = licenses.isc;
    maintainers = with maintainers; [ piranha ];
    platforms = platforms.linux ++ platforms.darwin;
  };
}
piranha commented 4 years ago

Hey! Thanks, I like the idea, but travis ci fails. :) I'm not developing a lot in Go right now so I'm not too familiar with Go modules and errors do not seem very understandable to me. Can you take a look at them? :)

a-h commented 4 years ago

I fixed the tests. I'd never seen cram before, looks like a useful tool.

If a project uses Go modules (has a go.mod file), there's no need to do a go get before building, go build will automatically download any missing packages and store them in a global cache, so I removed it.

However, the first thing the cram test was doing was building goreplace using the package name. This makes Go look for the package in the GOPATH, so it failed because the removal of the go get command from the Makefile meant that the required dependencies weren't there.

I fixed it by switching the test to building gr based on the source code file path instead of the package name.

piranha commented 4 years ago

Makes sense, thanks! :-)