Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jcmfernandes/go-tools-binstubs
Automatically generate binstubs for the tools in your golang project :sloth:
https://github.com/jcmfernandes/go-tools-binstubs
binstubs go golang tools
Last synced: 2 months ago
JSON representation
Automatically generate binstubs for the tools in your golang project :sloth:
- Host: GitHub
- URL: https://github.com/jcmfernandes/go-tools-binstubs
- Owner: jcmfernandes
- License: bsd-3-clause
- Created: 2024-04-10T09:14:30.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-09-13T11:09:17.000Z (3 months ago)
- Last Synced: 2024-10-09T16:42:41.886Z (2 months ago)
- Topics: binstubs, go, golang, tools
- Language: Go
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `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:``` yaml
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.2. 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`:``` yaml
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](https://github.com/brasic/binstubs).