commandx

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasBash added in v0.0.2

func HasBash() bool

HasBash 保留兼容:原语义是检查系统是否有 bash。 现在底层改用 mvdan.cc/sh 的内置解释器,已经不依赖系统 bash, 但维持函数行为以兼容外部调用方的判断逻辑。

Types

type CommandResult

type CommandResult struct {
	Stdout  bytes.Buffer
	Stderr  bytes.Buffer
	Status  int
	Success bool
	Err     error
}

func RunBashCommand added in v0.0.2

func RunBashCommand(command string, ops ...Option) *CommandResult

RunBashCommand 把入参当作一段 shell 源码交给内置解释器执行, 支持管道、重定向、变量展开等 bash 语法。

func RunCommand

func RunCommand(command []string, ops ...Option) *CommandResult

RunCommand 按 argv 形式执行命令。 内部会把参数做 POSIX shell 转义后拼成一行脚本,再交给解释器执行, 因此参数里的空格、引号、$ 等不会被二次解释,等价于直接 exec 的语义。

func RunCommandForLast

func RunCommandForLast(commands [][]string, ops ...Option) (bool, *CommandResult)

RunCommandForLast run commands and return last result

func (*CommandResult) OutputOrFatal

func (r *CommandResult) OutputOrFatal()

func (*CommandResult) SimpleLog added in v0.0.3

func (r *CommandResult) SimpleLog() string

type Option

type Option func(o *option)

func WithDir

func WithDir(dir string) Option

func WithRedirectStderr added in v0.0.3

func WithRedirectStderr() Option

func WithTimeout added in v0.0.2

func WithTimeout(timeout time.Duration) Option

Jump to

Keyboard shortcuts

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