cmd

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: MIT Imports: 5 Imported by: 9

Documentation

Overview

Package cmd offers functions for running programs in a Shell-like way.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(a *goyek.A, cmdLine string, opts ...Option) bool

Exec runs the command. It calls a.Error[f] and returns false in case of any problems. Example usage:

cmd.Exec(a, "FOO=foo BAR=baz ./foo --bar=baz", cmd.Dir("pkg"))
Example
goyek.Define(goyek.Task{
	Name:  "diff",
	Usage: "git diff",
	Action: func(a *goyek.A) {
		cmd.Exec(a, "git diff --exit-code")

		sb := &strings.Builder{}
		out := io.MultiWriter(a.Output(), sb)
		cmd.Exec(a, "git status --porcelain", cmd.Stdout(out))
		if sb.Len() > 0 {
			a.Error("git status --porcelain returned output")
		}
	},
})
Output:

Types

type Option

type Option func(a *goyek.A, cmd *exec.Cmd)

Option configures the command.

func Dir

func Dir(s string) Option

Dir is an option to set the working directory.

func Env

func Env(k, v string) Option

Env is an option to set an environment variable.

func Stderr

func Stderr(w io.Writer) Option

Stderr is an option to set the standard error.

func Stdin

func Stdin(r io.Reader) Option

Stdin is an option to set the standard input.

func Stdout

func Stdout(w io.Writer) Option

Stdout is an option to set the standard output.

Jump to

Keyboard shortcuts

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