gobin

package module
v0.1.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2024 License: Apache-2.0 Imports: 20 Imported by: 1

README

gobin

The command-line tool gobin installs the binaries in ~/go/bin or project-local directories according to the versions specified in the package list file. It is useful for managing Go tools that are not installed globally in $GOBIN .

Features

  • Installs and executes Go program packages of the versions specified in go.mod file.
  • Installs and executes Go packages of the versions specified in package manifest file.
  • Caches executed binaries for reuse.
  • Cached binaries can be executed even if the environment is offline.

Usage

To install:

go install github.com/knaka/cmd/gobin@latest

Executed packages are cached for later reuse. You can omit the @... version suffix for packages listed in the go.mod file. In that case, the binaries are cached in the same directory as the go.mod file.

$ cat Gobinfile
golang.org/x/tools/cmd/goyacc@latest
github.com/hairyhenderson/gomplate/v4/cmd/gomplate@latest
$ gobin run goyacc --help # Binaries are stored in the same directory as the Gobinfile 
Usage of ...
$

You can use commands in Go generate without installing them globally in $GOBIN as follows:

$ curl https://raw.githubusercontent.com/knaka/gobin/main/gobin-run.go -o gobin-run.go
$ echo golang.org/x/tools/cmd/stringer@v0.11 >> Gobinfile
$ echo github.com/sqlc-dev/sqlc/cmd/sqlc@latest >> Gobinfile

You can write additional information to Gobinfile entries as follows:

github.com/sqlc-dev/sqlc/cmd/sqlc@latest tags=foo,bar requires=command1,command2 # comment. “tags” for build tags, “requires” for the commands required to run the command.

Or record the module of the program package to go.mod file as described in “Go Wiki: Go Modules - The Go Programming Language”:

//go:build tools
package main

import _ "golang.org/x/tools/cmd/stringer"

then, add the following to the source code:

package foo

//go:generate -command stringer go run gobin-run.go golang.org/x/tools/cmd/stringer
//go:generate stringer -type Fruit .

//go:generate -command sqlc go run gobin-run.go sqlc
//go:generate sqlc generate

For managing "Go generate" dependencies between source and generated files, it is beneficial to use in combination with go-generate-fast.

package foo

//go:generate -command sqlc go run gobin-run.go sqlc

//go:generate_input ./sqlc.yaml ./schema*.sql ./migrations/*.sql
//go:generate_output ./sqlcgen/models.go
//go:generate sqlc generate

Usage as library

You can use gobin as a library mainly in task-runner written in Go.

TBD

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command added in v0.0.2024080712

func Command(args ...string) (cmd *exec.Cmd, err error)

func CommandEx

func CommandEx(args []string, opts ...Option) (cmd *exec.Cmd, err error)

func Install added in v0.0.2024080712

func Install(patterns ...string) (cmdPath string, err error)

func InstallEx added in v0.0.2024080712

func InstallEx(patterns []string, opts ...Option) (cmdPath string, err error)

func Run added in v0.0.2024080712

func Run(args ...string) (errExit *exec.ExitError, err error)

func RunEx added in v0.0.2024080712

func RunEx(args []string, opts ...Option) (errExit *exec.ExitError, err error)

func UpdateEx added in v0.0.2024080712

func UpdateEx(patterns []string, opts ...Option) (err error)

Types

type ListEntry added in v0.1.5

type ListEntry struct {
	Pkg           string
	Version       string
	LockedVersion string
}

func List added in v0.1.5

func List(global bool) (ret []*ListEntry, err error)

type Option added in v0.0.2024080712

type Option func(params *installParams) error

func Global added in v0.0.2024080712

func Global(f bool) Option

func Silent added in v0.1.5

func Silent(f bool) Option

Silent sets the silent flag to suppress normal log output.

func Verbose

func Verbose(f bool) Option

Verbose sets the verbose flag to enable verbose log output.

func WithDir

func WithDir(dir string) Option

func WithEnv

func WithEnv(env []string) Option

func WithGobinPath

func WithGobinPath(f bool) Option

func WithStderr

func WithStderr(stderr io.Writer) Option

func WithStdin

func WithStdin(stdin io.Reader) Option

func WithStdout

func WithStdout(stdout io.Writer) Option

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL