package hexec
import "github.com/gohugoio/hugo/common/hexec"
Index ¶
- Variables
- func InPath(binaryName string) bool
- func IsNotFound(err error) bool
- func LookPath(binaryName string) string
- func SafeCommand(name string, arg ...string) (*exec.Cmd, error)
- type Exec
- func New(cfg security.Config, workingDir string, log loggers.Logger) *Exec
- func (e *Exec) New(name string, arg ...any) (Runner, error)
- func (e *Exec) Npx(name string, arg ...any) (Runner, error)
- func (e *Exec) Sec() security.Config
- type NotFoundError
- type Runner
Variables ¶
var WithContext = func(ctx context.Context) func(c *commandeer) { return func(c *commandeer) { c.ctx = ctx } }
var WithDir = func(dir string) func(c *commandeer) { return func(c *commandeer) { c.dir = dir } }
var WithEnviron = func(env []string) func(c *commandeer) { return func(c *commandeer) { setOrAppend := func(s string) { k1, _ := config.SplitEnvVar(s) var found bool for i, v := range c.env { k2, _ := config.SplitEnvVar(v) if k1 == k2 { found = true c.env[i] = s } } if !found { c.env = append(c.env, s) } } for _, s := range env { setOrAppend(s) } } }
var WithStderr = func(w io.Writer) func(c *commandeer) { return func(c *commandeer) { c.stderr = w } }
var WithStdin = func(r io.Reader) func(c *commandeer) { return func(c *commandeer) { c.stdin = r } }
var WithStdout = func(w io.Writer) func(c *commandeer) { return func(c *commandeer) { c.stdout = w } }
Functions ¶
func InPath ¶
InPath reports whether binaryName is in $PATH.
func IsNotFound ¶
IsNotFound reports whether this is an error about a binary not found.
func LookPath ¶
LookPath finds the path to binaryName in $PATH. Returns "" if not found.
func SafeCommand ¶
SafeCommand is a wrapper around os/exec Command which uses a LookPath implementation that does not search in current directory before looking in PATH. See https://github.com/cli/safeexec and the linked issues.
Types ¶
type Exec ¶
type Exec struct {
// contains filtered or unexported fields
}
Exec enforces a security policy for commands run via os/exec.
func New ¶
New creates a new Exec using the provided security config.
func (*Exec) New ¶
func (*Exec) Npx ¶
Npx will in order: 1. Try fo find the binary in the WORKINGDIR/node_modules/.bin directory. 2. If not found, and npx is available, run npx --no-install <name> <args>. 3. Fall back to the PATH. If name is "tailwindcss", we will try the PATH as the second option.
func (*Exec) Sec ¶
Sec returns the security policies this Exec is configured with.
type NotFoundError ¶
type NotFoundError struct {
// contains filtered or unexported fields
}
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
type Runner ¶
type Runner interface { Run() error StdinPipe() (io.WriteCloser, error) }
Runner wraps a *os.Cmd.
Source Files ¶
- Version
- v0.144.2 (latest)
- Published
- Feb 19, 2025
- Platform
- linux/amd64
- Imports
- 17 packages
- Last checked
- 13 hours ago –
Tools for package owners.