Documentation ¶
Overview ¶
Package binwrapper provides executable wrapper that makes command line tools seamlessly available as local golang dependencies. Inspired by and partially ported from npm package bin-wrapper: https://github.com/kevva/bin-wrapper
Index ¶
- type BinWrapper
- func (b *BinWrapper) Arg(name string, values ...string) *BinWrapper
- func (b *BinWrapper) Args() []string
- func (b *BinWrapper) AutoExe() *BinWrapper
- func (b *BinWrapper) CombinedOutput() []byte
- func (b *BinWrapper) Debug() *BinWrapper
- func (b *BinWrapper) Dest(dest string) *BinWrapper
- func (b *BinWrapper) Env(env []string) *BinWrapper
- func (b *BinWrapper) ExecPath(execPath string) *BinWrapper
- func (b *BinWrapper) Kill() error
- func (b *BinWrapper) Path() string
- func (b *BinWrapper) Reset() *BinWrapper
- func (b *BinWrapper) Run(arg ...string) error
- func (b *BinWrapper) SetStdOut(writer io.Writer) *BinWrapper
- func (b *BinWrapper) SkipDownload() *BinWrapper
- func (b *BinWrapper) Src(src *Src) *BinWrapper
- func (b *BinWrapper) StdErr() []byte
- func (b *BinWrapper) StdIn(reader io.Reader) *BinWrapper
- func (b *BinWrapper) StdOut() []byte
- func (b *BinWrapper) Strip(value int) *BinWrapper
- func (b *BinWrapper) Timeout(timeout time.Duration) *BinWrapper
- type Src
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinWrapper ¶
type BinWrapper struct {
// contains filtered or unexported fields
}
BinWrapper wraps executable and provides convenient methods to interact with
func NewBinWrapper ¶
func NewBinWrapper() *BinWrapper
NewBinWrapper creates BinWrapper instance
Example ¶
Example of wrapping cwebp command line tool
base := "https://storage.googleapis.com/downloads.webmproject.org/releases/webp/" bin := binwrapper.NewBinWrapper(). Src( binwrapper.NewSrc(). URL(base + "libwebp-0.6.0-mac-10.12.tar.gz"). Os("darwin")). Src( binwrapper.NewSrc(). URL(base + "libwebp-0.6.0-linux-x86-32.tar.gz"). Os("linux"). Arch("x86")). Src( binwrapper.NewSrc(). URL(base + "libwebp-0.6.0-linux-x86-64.tar.gz"). Os("linux"). Arch("x64")). Src( binwrapper.NewSrc(). URL(base + "libwebp-0.6.0-windows-x64.zip"). Os("win32"). Arch("x64"). ExecPath("cwebp.exe")). Src( binwrapper.NewSrc(). URL(base + "libwebp-0.6.0-windows-x86.zip"). Os("win32"). Arch("x86"). ExecPath("cwebp.exe")). Strip(2). Dest("vendor/cwebp"). ExecPath("cwebp") err := bin.Run("-version") fmt.Printf("stdout: %s\n", string(bin.StdOut())) fmt.Printf("stderr: %s\n", string(bin.StdErr())) fmt.Printf("err: %v\n", err)
Output:
func (*BinWrapper) Arg ¶
func (b *BinWrapper) Arg(name string, values ...string) *BinWrapper
Arg adds command line argument to run the binary with.
func (*BinWrapper) Args ¶
func (b *BinWrapper) Args() []string
Args returns arguments were added with Arg method
func (*BinWrapper) AutoExe ¶
func (b *BinWrapper) AutoExe() *BinWrapper
AutoExe adds .exe extension for windows executable path
func (*BinWrapper) CombinedOutput ¶
func (b *BinWrapper) CombinedOutput() []byte
CombinedOutput returns combined executable's stdout and stderr
func (*BinWrapper) Dest ¶
func (b *BinWrapper) Dest(dest string) *BinWrapper
Dest accepts a path which the files will be downloaded to
func (*BinWrapper) Env ¶
func (b *BinWrapper) Env(env []string) *BinWrapper
Env specifies the environment of the executable. If Env is nil, Run uses the current process's environment. Elements of env should be in form: "ENV_VARIABLE_NAME=value"
func (*BinWrapper) ExecPath ¶
func (b *BinWrapper) ExecPath(execPath string) *BinWrapper
ExecPath define a file to use as the binary
func (*BinWrapper) Path ¶
func (b *BinWrapper) Path() string
Path returns the full path to the binary
func (*BinWrapper) Reset ¶
func (b *BinWrapper) Reset() *BinWrapper
Reset removes all arguments set with Arg method, cleans StdOut and StdErr
func (*BinWrapper) Run ¶
func (b *BinWrapper) Run(arg ...string) error
Run runs the binary with provided arg list. Arg list is appended to args set through Arg method Returns context.DeadlineExceeded in case of timeout
func (*BinWrapper) SetStdOut ¶
func (b *BinWrapper) SetStdOut(writer io.Writer) *BinWrapper
SetStdOut set writer to write executable's stdout
func (*BinWrapper) SkipDownload ¶
func (b *BinWrapper) SkipDownload() *BinWrapper
SkipDownload skips downloading a file
func (*BinWrapper) Src ¶
func (b *BinWrapper) Src(src *Src) *BinWrapper
Src adds a Src to BinWrapper
func (*BinWrapper) StdErr ¶
func (b *BinWrapper) StdErr() []byte
StdErr returns the executable's stderr after Run was called
func (*BinWrapper) StdIn ¶
func (b *BinWrapper) StdIn(reader io.Reader) *BinWrapper
StdIn sets reader to read executable's stdin from
func (*BinWrapper) StdOut ¶
func (b *BinWrapper) StdOut() []byte
StdOut returns the binary's stdout after Run was called
func (*BinWrapper) Strip ¶
func (b *BinWrapper) Strip(value int) *BinWrapper
Strip strips a number of leading paths from file names on extraction.
func (*BinWrapper) Timeout ¶
func (b *BinWrapper) Timeout(timeout time.Duration) *BinWrapper
Timeout sets timeout for the command. By default it's 0 (binary will run till end).
type Src ¶
type Src struct {
// contains filtered or unexported fields
}
Src defines executable source
func (*Src) Arch ¶
Arch tie the source to a specific arch. Possible values are same as runtime.GOARCH