Giter Club home page Giter Club logo

go-tools-binstubs's Introduction

go-tools-binstubs

Automatically generate binstubs for the tools in your golang project

go-tools-binstubs is a nearly zero-configuration way to generate project binstubs that run the correct version of a go command tracked in your go.mod file.

  1. Create a tools.yaml file that looks like this, pointing to the executable program path for each dependency:
package: tools
global_go_run_modifiers:
  - '-x'
build_tags:
  - tools
  - ignore
output_go_file_path: tools.go
output_binstubs_directory_path: bin
tools:
  - package: github.com/jcmfernandes/go-tools-binstubs
    ignore: false
    binstub: go-tools-binstubs
    go_run_modifiers:
      - '-work'
    override_global_go_run_modifiers: false
    binstub_modifiers:
      - '-help'

Or run go run github.com/jcmfernandes/go-tools-binstubs -gentemplate tools.yaml to quickly generate a YAML template.

  1. Run go run github.com/jcmfernandes/go-tools-binstubs -input tools.yaml to create corresponding shell scripts in output_binstubs_directory_path (defaults to bin) and go file in output_go_file_path (defaults to tools.go).

Using a separate go.mod file

It's a good practice to create a separate go.mod file for your project's tool. Let's say you have the following project setup:

.
├── go.mod
├── go.sum
├── internal
│   └── tools
│       ├── go.mod
│       ├── tools.yaml
│       └── go.sum
└── main.go

And you want it to look like the following:

.
├── bin
│   └── a-tool
├── go.mod
├── go.sum
├── internal
│   └── tools
│       ├── go.mod
│       ├── tools.yaml
│       ├── tools.go
│       └── go.sum
└── main.go

You'll have to change your binstubs -modfile to ./internal/tools/go.mod to make this work. Since you don't want to hardcode paths in your binstubs (you want them to work on everyone's machine), every binstub ships with bash variable binstubAbsParentDirectory that contains the runtime absolute path to the binstubs parent directory. You can use it to change your binstubs -modfile:

package: tools
global_go_run_modifiers:
  - '-modfile=${binstubAbsParentDirectory}/../internal/tools/go.mod'
output_binstubs_directory_path: "../../bin"
tools:
  - package: github.com/jcmfernandes/go-tools-binstubs

And voilà!

Acknowledgements

go-tools-binstubs started as a fork of binstubs.

go-tools-binstubs's People

Contributors

jcmfernandes avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.