command

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package command provides utilities to manage and execute shell commands. It supports executing individual commands, combining multiple commands into one, and running those commands within a specified environment. Additionally, the package offers methods for initializing, executing, and handling installation of commands, often in conjunction with external tools like mvdan/sh for shell script parsing and execution.

The Commands type represents a collection of shell commands that can be processed together. The Command type encapsulates a single shell command, with methods to manipulate, format, and execute it.

Index

Constants

This section is empty.

Variables

View Source
var ErrRun = errors.New("running shell command")

ErrRun indicates a failure while executing a shell command.

Functions

This section is empty.

Types

type Command

type Command string

Command represents a shell command that can be executed.

func (*Command) From

func (c *Command) From(command string)

From sets the Command value from the provided command string.

func (*Command) Shell

func (c *Command) Shell(ctx context.Context, env ...string) (string, error)

Shell executes the Command using mvdan/sh shell interpreter. It captures both stdout and stderr output, supports environment variables, and returns the stdout output or an error if execution fails.

func (*Command) String

func (c *Command) String() string

String returns the string representation of the Command.

type Commands

type Commands struct {
	Data         install.Metadata                     `yaml:"-"`
	Commands     unmarshal.SingleOrSliceType[Command] `yaml:"commands"`
	AllowFailure bool                                 `yaml:"allow-failure"`
	ExitOnError  bool                                 `yaml:"exit-on-error"`
}

Commands represents a collection of shell commands that can be executed together.

func (*Commands) Combined

func (e *Commands) Combined() Command

Combined joins all commands into a single Command with proper shell options. Prepends shell error handling options based on ExitOnError setting and joins commands with semicolons.

func (*Commands) Run

func (e *Commands) Run(ctx context.Context, env env.Env) (output string, err error)

Run executes the combined commands with the provided environment variables. Returns the command output and any execution errors, respecting AllowFailure setting.

func (*Commands) UnmarshalYAML

func (e *Commands) UnmarshalYAML(node ast.Node) error

UnmarshalYAML implements custom YAML unmarshaling for Commands. It supports both single command strings and command arrays.

Jump to

Keyboard shortcuts

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