execx

package
v0.0.0-...-4450389 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package `execx` provides utility functions that supplement the stdlib package `os/exec`.

`MustLookTool()` reliably locates external command line tools during program startup.

Example
package main

import (
	"fmt"
	"os/exec"

	"github.com/nogproject/nog/backend/pkg/execx"
)

var bash = execx.MustLookTool(execx.ToolSpec{
	Program:   "bash",
	CheckArgs: []string{"--version"},
	CheckText: "GNU bash",
})

func main() {
	out, _ := exec.Command(bash.Path, "-c", "echo hello").Output()
	fmt.Println(string(out))
}
Output:

hello

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tool

type Tool struct {
	Path string
}

func LookTool

func LookTool(s ToolSpec) (*Tool, error)

func MustLookTool

func MustLookTool(s ToolSpec) *Tool

`MustLookTool()` tries to run `s.Program` with `s.CheckArgs` and verifies that its output contains `s.CheckText`. If anything fails, `MustLookTool()` panics.

type ToolSpec

type ToolSpec struct {
	Program   string
	CheckArgs []string
	CheckText string
}

`ToolSpec` is used to tell `MustLookTool()` how to look for an external tool.

Jump to

Keyboard shortcuts

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