The forgotten go tool that executes and caches binaries included in go.mod files.

gomodrun

Build Status Release Coverage Status Go Report Card Godocs

The forgotten go tool that executes and caches binaries included in go.mod files. This makes it easy to version cli tools in your projects such as golangci-lint and ginkgo that are versioned locked to what you specify in go.mod. Binaries are cached by go version and package version.

Example

  # Run a linter
  gomodrun golangci-lint run

  # Convert a JSON object to a Go struct, properly passing in stdin.
  echo example.json | gomodrun gojson > example.go

  # Specifiy alternative root directory containing a go.mod and tools file.
  gomodrun -r ./alternative-tools-dir golangci-lint run

  # Clean your .gomodrun folder of unused binaries.
  gomodrun --tidy

Installation

homebrew (OSX / Linux):

brew install dustinblackman/tap/gomodrun

scoop (Windows):

$ scoop bucket add dustinblackman https://github.com/dustinblackman/scoop-bucket.git
$ scoop install gomodrun

deb/rpm/apk (Linux):

Download the .deb, .rpm or .apk from the releases page and install with dpkg -i, rpm -i, or apk add --allow-untrusted respectively.

nix (Linux):

nix-env -f '<nixpkgs>' -iA nur.repos.dustinblackman.gomodrun

manually:

Download the pre-compiled binaries from the releases page and copy to the desired location.

go/master branch:

go get -u github.com/dustinblackman/gomodrun/cmd/gomodrun

Usage

gomodrun works by using a tools.go (or any other name) file that sits in the root of your project that contains all the CLI dependencies you want bundled in to your go.mod. Note the // +build tools at the top of the file is required, and allows you to name your tools file anything you like.

tools.go

// +build tools

package myapp

import (
	_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
	_ "github.com/onsi/ginkgo/ginkgo"
)

Run go build tools.go to add the dependencies to your go.mod. The build is expected to fail.

CLI

You can run your tools by prefixing gomodrun. A binary will be built and cached in .gomodrun in the root of your project, allowing all runs after the first to be nice and fast.

  gomodrun golangci-lint run

Programmatically

You can also use gomodrun as a library.

package main

import (
	"os"

	"github.com/dustinblackman/gomodrun"
)

func main() {
	exitCode, err := gomodrun.Run("golangci-lint", []string{"run"}, &gomodrun.Options{
		Stdin:   os.Stdin,
		Stdout:  os.Stdout,
		Stderr:  os.Stderr,
		Env:     os.Environ(),
		PkgRoot: "",
	})
}

License

MIT

Owner
Dustin Blackman
Senior Lead Software Engineer, Full Stack
Dustin Blackman
Similar Resources

Purpose: dump slack messages, users and files using browser token and cookie.

Slack Dumper Purpose: dump slack messages, users and files using browser token and cookie. Typical usecase scenarios: You want to archive your private

Jan 2, 2023

Go-keymap - Generate keymap.c, layers.h and keymap.svg from visual keymaps defined through keymaps.json and .layer files

Go-keymap - Generate keymap.c, layers.h and keymap.svg from visual keymaps defined through keymaps.json and .layer files

generating keymap.c This utility can generate a keymap.c, layers.h and keymap.sv

Feb 15, 2022

Easily create & extract archives, and compress & decompress files of various formats

archiver Introducing Archiver 3.1 - a cross-platform, multi-format archive utility and Go library. A powerful and flexible library meets an elegant CL

Jan 7, 2023

Visualize how a projects source code is distributed among its files and folders

Visualize how a projects source code is distributed among its files and folders

Source Code Visualizer Visualize the code distribution in a project. Applications Applications include: Visualizing code distribution for more educate

Jul 31, 2022

Simple 'UserKit' for Malware written in Go. Startup, Hidden Files, Critical Process and Registry Watcher

GoUserKit Simple UserKit for Malware written in Go Features Makes Process Critical (NtSetInformationProcess) Hides Files Simple Add to Startup (HKCU R

Jan 3, 2023

DSV Parallel Processor takes input files and query specification via a spec file

DSV Parallel Processor Spec file DSV Parallel Processor takes input files and query specification via a spec file (conventionally named "spec.toml").

Oct 9, 2021

A ready to use Pastebin written in Go Lang, fork the files and start editing/using it.

A ready to use Pastebin written in Go Lang, fork the files and start editing/using it.

Dec 31, 2021

View the script files in the original Resident Evil 2 / Biohazard 2 as pseudocode

View the script files in the original Resident Evil 2 / Biohazard 2 as pseudocode

Resident Evil 2 Script Viewer About You can view the script files in the original Resident Evil 2 / Biohazard 2 as pseudocode next to the original byt

Jan 20, 2022

🦉 Docuowl generates a static single-page documentation from Markdown files

🦉 Docuowl generates a static single-page documentation from Markdown files

🦉 Docuowl generates a static single-page documentation from Markdown files

Jan 2, 2023
Comments
  • Feature request: read go.mod not located in current directory

    Feature request: read go.mod not located in current directory

    Adding tools to my go.mod file screws with other declared dependencies. It'd be nice if gomodrun could take a parameter that specifies where to look for the tools file and go.mod, so I could keep my actual dependencies distinct from tooling dependencies

  • brew isntall Error

    brew isntall Error

    Hi I tried to install gomodrun with brew on MacBook Pro with Os Monterey but received these errors: image Thanks for any help, let me know if I can assist.

  • Fallback to default GOPATH if env var is not set

    Fallback to default GOPATH if env var is not set

    If the user has not set their GOPATH environment variable we incorrectly report that the desired sources has not been downloaded. We therefore make sure to fallback to a default value.

Renda is a go library that repeatedly executes any processes

Renda is a go library that repeatedly executes any processes.

Feb 7, 2022
TheOtherRolesInstaller - A simple tool to install the latest version of TheOtherRoles Mod

TheOtherRoles Installer This is a simple tool to install TheOtherRoles Mod for A

Sep 30, 2022
GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way to say thanks to the maintainers of the modules you use and the contributors of Go itself.
GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way  to say thanks to the maintainers of the modules you use and the contributors of Go itself.

Give thanks (in the form of a GitHub ★) to your fellow Go modules maintainers. About GoThanks performs the following operations Sends a star to Go's r

Dec 24, 2022
A toy repo used to test the functionality of "go mod why".

Mod Why Test Discussion From a module perspective: The main module (github.com/ejweber/mod-why-test) has a single direct dependency (github.com/ejwebe

Dec 1, 2021
go.mod file is the root of dependency management in Go

go.mod file is the root of dependency management in Go. All the modules which are needed or to be used in the project are maintained in go.mod file. I

Feb 9, 2022
Find strings in Go binaries

gostringsr2 gostringsr2 extracts strings from a Go binary using radare2. Tested with radare2 3.7.0, Python 3.7, r2pipe 1.4.1, on OS X and Linux. Teste

Oct 20, 2022
A framework for constructing self-spreading binaries
A framework for constructing self-spreading binaries

A framework that aids in creation of self-spreading software Requirements go get -u github.com/redcode-labs/Coldfire go get -u github.com/yelinaung/go

Jan 2, 2023
Ghdl - A much more convenient way to download GitHub release binaries on the command line, works on Win & Unix-like systems

ghdl Memorize ghdl as github download ghdl is a fast and simple program (and als

Oct 12, 2022
elPrep: a high-performance tool for analyzing sequence alignment/map files in sequencing pipelines.
elPrep: a high-performance tool for analyzing sequence alignment/map files in sequencing pipelines.

Overview elPrep is a high-performance tool for analyzing .sam/.bam files (up to and including variant calling) in sequencing pipelines. The key advant

Nov 2, 2022
Tool to easily rename or move a bunch of files with a text editor of your choice
Tool to easily rename or move a bunch of files with a text editor of your choice

batch-rename With batch-rename you can utilize your favorite text editor to rename or move a bunch of files at once. It doesn't come with any features

Nov 2, 2022