osexec

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 17 Imported by: 16

README

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

osexec

Simple utilities to use Golang's os/exec package.


CHINESE README

中文说明

Features

  • Custom Execution Configurations: Execute commands with customizable environment variables, working paths, and shell options
  • Chainable API: Fluent interface when building command configurations
  • Shell Support: Built-in support with bash, zsh, and sh shells
  • Debug Modes: Multiple debug levels to manage command and output options
  • Exit Code Handling: Accept specific exit codes as success
  • Environment Variables: Simple environment variable management
  • Path Management: Execute commands in specific paths

Installation

go get github.com/yylego/osexec

Quick Start

Basic Usage
package main

import (
	"fmt"

	"github.com/yylego/must"
	"github.com/yylego/osexec"
)

func main() {
	// Execute simple command
	output, err := osexec.Exec("echo", "abc")
	must.Done(err)
	fmt.Println("Output:", string(output))

	// Execute command in specific path
	output, err = osexec.ExecInPath("/tmp", "pwd")
	must.Done(err)
	fmt.Println("Current path:", string(output))

	// Execute with environment variables
	envs := []string{"MY_VAR=hello", "ANOTHER_VAR=world"}
	output, err = osexec.ExecInEnvs(envs, "printenv", "MY_VAR")
	must.Done(err)
	fmt.Println("Environment value:", string(output))
}

⬆️ Source

Advanced Usage
package main

import (
	"fmt"

	"github.com/yylego/done"
	"github.com/yylego/osexec"
)

func main() {
	// Create configuration with chainable methods
	config := osexec.NewCommandConfig().
		WithBash().
		WithDebugMode(osexec.SHOW_COMMAND)

	// Execute shell command
	output, err := config.Exec("echo $HOME")
	done.Done(err)
	fmt.Println("Home path:", string(output))

	// Execute command with custom environment
	config = config.NewConfig().
		WithEnvs([]string{"GREETING=Hello", "NAME=Go"}).
		WithBash()

	output, err = config.Exec("echo", "$GREETING $NAME!")
	done.Done(err)
	fmt.Println("Message:", string(output))
}

⬆️ Source

CommandConfig - Advanced Usage

CommandConfig provides a flexible method to configure and execute commands with chainable methods.

Creating Configuration
config := osexec.NewCommandConfig()
Shell Execution

Execute commands using different shells:

// Using bash
config := osexec.NewCommandConfig().WithBash()
output, err := config.Exec("echo $SHELL")

// Using zsh
config := osexec.NewCommandConfig().WithZsh()
output, err := config.Exec("echo 'ZSH Command'")

// Using sh
config := osexec.NewCommandConfig().WithSh()
output, err := config.Exec("pwd")
Complex Shell Commands
config := osexec.NewCommandConfig().WithBash()

// Pipe commands
output, err := config.Exec("echo 'apple\nbanana\norange' | grep 'banana'")

// Command with variables
config.WithEnvs([]string{"GREETING=Hello", "NAME=World"})
output, err = config.Exec("echo", "$GREETING $NAME!")
Debug Modes

Manage command and output options:

// Complete debug mode - shows both command and output
config := osexec.NewCommandConfig().WithDebug()

// Show command just
config := osexec.NewCommandConfig().WithDebugMode(osexec.SHOW_COMMAND)

// Show outputs just
config := osexec.NewCommandConfig().WithDebugMode(osexec.SHOW_OUTPUTS)

// Quiet mode - no debug output
config := osexec.NewCommandConfig().WithDebugMode(osexec.QUIET)
Exit Code Handling

Accept specific exit codes as success:

// Accept exit code 1 as success with reason
config := osexec.NewCommandConfig().
	WithExpectExit(1, "DIFFERENCES FOUND")

output, err := config.Exec("diff", "file1.txt", "file2.txt")
// err becomes nil even if diff returns exit code 1

// Accept multiple exit codes
config := osexec.NewCommandConfig().
	WithTakeExits(map[int]string{
		1: "DIFFERENCES FOUND",
		2: "TROUBLE",
	})
Get Exit Code

Use ExecTake to get the exit code with fine-grained precision:

// ExecTake returns output, exit code, and error
output, exitCode, err := osexec.NewCommandConfig().
	WithExpectCode(1).
	ExecTake("diff", "file1.txt", "file2.txt")

// exitCode = 1 when files differ, exitCode = 0 when identical
fmt.Println("Exit code:", exitCode)
Chainable Configuration

Combine multiple configuration options:

config := osexec.NewCommandConfig().
	WithPath("/path/to/project").
	WithEnvs([]string{"ENV=production"}).
	WithBash().
	WithDebugMode(osexec.SHOW_COMMAND).
	WithExpectCode(1)

output, err := config.Exec("command-name", "arg1", "arg2")

API Reference

Configuration Methods
  • WithEnvs(envs []string): Sets custom environment variables
  • WithPath(path string): Sets the working path
  • WithShellType(shellType string): Sets the shell type (e.g., bash)
  • WithShellFlag(shellFlag string): Sets the shell flag (e.g., -c)
  • WithShell(shellType, shellFlag string): Sets both shell type and flag
  • WithBash(): Configures to use bash -c
  • WithZsh(): Configures to use zsh -c
  • WithSh(): Configures to use sh -c
  • WithDebug(): Enables complete debug mode
  • WithDebugMode(debugMode DebugMode): Sets specific debug mode
  • WithExpectExit(exitCode int, reason string): Adds expected exit code with reason
  • WithExpectCode(exitCode int): Adds expected exit code
  • WithTakeExits(takeExits map[int]string): Sets multiple expected exit codes
Execution Methods
  • Exec(name string, args ...string): Executes command and returns output
  • ExecTake(name string, args ...string): Executes command and returns output, exit code, and error
  • ExecWith(name string, args []string, prepare func(*exec.Cmd)): Executes with custom command setup
  • StreamExec(name string, args ...string): Executes command with pipe handling
  • ExecInPipe(name string, args ...string): Executes with stdout/stderr pipe processing
Debug Modes
  • QUIET: No debug output
  • DEBUG: Complete debug mode with command and output
  • SHOW_COMMAND: Show command just
  • SHOW_OUTPUTS: Show outputs just

Test Utilities

The osexectest package provides assistance functions used in writing tests that involve command execution.

Skipping Tests due to Missing Commands

When writing tests that depend on outside commands (e.g., zsh, git, tree), it's good practice to skip them if the needed command is not present in the test environment. The SkipIfCommandNotFound function helps you do this with ease.

package my_test

import (
    "testing"

    "github.com/yylego/osexec/osexectest"
)

func TestSomethingThatNeedsZsh(t *testing.T) {
    // This test will be skipped on its own if 'zsh' is not in the system's PATH.
    osexectest.SkipIfCommandNotFound(t, "zsh")

    // ... rest of the test code that uses 'zsh'
}

This avoids test failures in environments where specific command-line tools are not installed.

Skipping All Tests in TestMain

When all tests in a package depend on a specific command, use ExitIfCommandNotFound in TestMain to skip the entire test file:

package my_test

import (
    "testing"

    "github.com/yylego/osexec/osexectest"
)

func TestMain(m *testing.M) {
    // Exit with code 0 (skip) if 'bash' is not available
    osexectest.ExitIfCommandNotFound(m, "bash")
    m.Run()
}

To customize the exit code, use ExitWithCodeIfCommandNotFound:

func TestMain(m *testing.M) {
    // Exit with code 1 (failure) if 'bash' is not available
    osexectest.ExitWithCodeIfCommandNotFound(m, "bash", 1)
    m.Run()
}
Skipping Tests due to Missing Environment Variables

When tests depend on specific environment variables (e.g., API_KEY, DATABASE_URL), use SkipIfEnvNotSet to skip them gracefully:

func TestSomethingThatNeedsApiKey(t *testing.T) {
    // This test will be skipped if 'API_KEY' environment variable is not set
    osexectest.SkipIfEnvNotSet(t, "API_KEY")

    // ... rest of the test code that uses the API key
}

Use ExitIfEnvNotSet in TestMain to skip the entire test file when an environment variable is missing:

func TestMain(m *testing.M) {
    // Exit with code 0 (skip) if 'DATABASE_URL' is not set
    osexectest.ExitIfEnvNotSet(m, "DATABASE_URL")
    m.Run()
}

📄 License

MIT License - see LICENSE.


💬 Contact & Feedback

Contributions are welcome! Report bugs, suggest features, and contribute code:

  • 🐛 Mistake reports? Open an issue on GitHub with reproduction steps
  • 💡 Fresh ideas? Create an issue to discuss
  • 📖 Documentation confusing? Report it so we can improve
  • 🚀 Need new features? Share the use cases to help us understand requirements
  • Performance issue? Help us optimize through reporting slow operations
  • 🔧 Configuration problem? Ask questions about complex setups
  • 📢 Follow project progress? Watch the repo to get new releases and features
  • 🌟 Success stories? Share how this package improved the workflow
  • 💬 Feedback? We welcome suggestions and comments

🔧 Development

New code contributions, follow this process:

  1. Fork: Fork the repo on GitHub (using the webpage UI).
  2. Clone: Clone the forked project (git clone https://github.com/yourname/repo-name.git).
  3. Navigate: Navigate to the cloned project (cd repo-name)
  4. Branch: Create a feature branch (git checkout -b feature/xxx).
  5. Code: Implement the changes with comprehensive tests
  6. Testing: (Golang project) Ensure tests pass (go test ./...) and follow Go code style conventions
  7. Documentation: Update documentation to support client-facing changes
  8. Stage: Stage changes (git add .)
  9. Commit: Commit changes (git commit -m "Add feature xxx") ensuring backward compatible code
  10. Push: Push to the branch (git push origin feature/xxx).
  11. PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.

Please ensure tests pass and include relevant documentation updates.


🌟 Support

Welcome to contribute to this project via submitting merge requests and reporting issues.

Project Support:

  • Give GitHub stars if this project helps you
  • 🤝 Share with teammates and (golang) programming friends
  • 📝 Write tech blogs about development tools and workflows - we provide content writing support
  • 🌟 Join the ecosystem - committed to supporting open source and the (golang) development scene

Have Fun Coding with this package! 🎉🎉🎉


GitHub Stars

starring

Documentation

Overview

Package osexec provides simple and flexible command execution utilities

osexec 提供简单而灵活的命令执行工具包

Provides enhanced abstraction on os/exec with customizable configurations 提供增强的 os/exec 抽象接口,支持可定制的配置选项

Supports custom environment variables, working paths, and shell options 支持自定义环境变量、工作路径和 shell 选项

Includes debug modes and intelligent error handling capabilities 包含调试模式和智能错误处理能力

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(name string, args ...string) ([]byte, error)

Exec executes a command. Exec 执行一个命令且获得结果。

func ExecInEnvs

func ExecInEnvs(envs []string, name string, args ...string) ([]byte, error)

ExecInEnvs executes a command with custom environment variables. ExecInEnvs 使用自定义环境变量执行一个命令。

func ExecInPath

func ExecInPath(path string, name string, args ...string) ([]byte, error)

ExecInPath executes a command in a specified DIR. ExecInPath 在指定的 DIR 中执行一个命令。

func ExecXshRun

func ExecXshRun(shellType, shellFlag string, name string, args ...string) ([]byte, error)

ExecXshRun executes a command using a specific shell type and shell flag. ExecXshRun 使用指定的 shell 类型和 shell 标志执行一个命令。

func GetDebugMode

func GetDebugMode() bool

GetDebugMode returns the package-wide debug mode status GetDebugMode 返回包级别的调试模式状态

func SetDebugMode

func SetDebugMode(enable bool)

SetDebugMode sets the package-wide debug mode SetDebugMode 设置包级别的调试模式

Types

type CommandConfig

type CommandConfig struct {
	Envs      []string                     // Custom environment variables // 自定义环境变量
	Path      string                       // Execution path // 执行路径
	ShellType string                       // Type of shell to use, e.g., bash, zsh // shell 类型,例如 bash,zsh
	ShellFlag string                       // Shell flag, e.g., "-c" // Shell 参数,例如 "-c"
	DebugMode DebugMode                    // Debug mode setting // 调试模式设置
	MatchPipe func(outputLine string) bool // Function to match output lines in pipe mode // 管道模式下匹配输出行的函数
	MatchMore bool                         // Continue matching even when matched // 即使匹配成功也继续匹配
	TakeExits map[int]string               // Map of expected exit codes with reasons // 预期退出码及其原因的映射表
}

CommandConfig represents the configuration when executing shell commands CommandConfig 表示执行 shell 命令时的配置

func NewCommandConfig

func NewCommandConfig() *CommandConfig

NewCommandConfig creates and returns a new CommandConfig instance. NewCommandConfig 创建并返回一个新的 CommandConfig 实例。

func (*CommandConfig) Exec

func (c *CommandConfig) Exec(name string, args ...string) ([]byte, error)

Exec executes a shell command with the specified name and arguments, using the CommandConfig configuration. Exec 使用 CommandConfig 的配置执行带有指定名称和参数的 shell 命令。

func (*CommandConfig) ExecInPipe

func (c *CommandConfig) ExecInPipe(name string, args ...string) ([]byte, error)

ExecInPipe executes a shell command with the specified name and arguments, using the CommandConfig configuration, and returns the output as a byte slice. ExecInPipe 使用 CommandConfig 的配置执行带有指定名称和参数的 shell 命令,并返回输出的字节切片。

func (*CommandConfig) ExecTake

func (c *CommandConfig) ExecTake(name string, args ...string) ([]byte, int, error)

ExecTake executes a command and returns output, exit code, and an issue if one exists Returns exit code enabling fine-grained handling of command outcomes Exit code 0 indicates success, non-zero indicates various conditions

ExecTake 执行命令并返回输出、退出码和错误(如果有的话) 返回退出码以便精细处理命令结果 退出码 0 表示成功,非零表示各种情况

func (*CommandConfig) ExecWith

func (c *CommandConfig) ExecWith(name string, args []string, prepare func(command *exec.Cmd)) ([]byte, error)

ExecWith executes a command with custom exec.Cmd preparation Allows setting stdin, extra env vars, and additional cmd fields via prepare callback

ExecWith 执行命令,支持自定义 exec.Cmd 配置 通过 prepare 回调可设置 stdin、额外环境变量和其它 cmd 字段

func (*CommandConfig) IsShowCommand

func (c *CommandConfig) IsShowCommand() bool

IsShowCommand checks if the command should be displayed based on the debug mode IsShowCommand 检查是否应根据调试模式显示命令

func (*CommandConfig) IsShowOutputs

func (c *CommandConfig) IsShowOutputs() bool

IsShowOutputs checks if the command results should be displayed based on the debug mode IsShowOutputs 检查是否应根据调试模式显示命令结果

func (*CommandConfig) Must

func (*CommandConfig) NewConfig

func (c *CommandConfig) NewConfig() *CommandConfig

NewConfig creates a shallow clone of the CommandConfig instance. NewConfig 克隆一个新的 CommandConfig 实例,以便于实现总配置和子配置分隔.

func (*CommandConfig) Omit

func (*CommandConfig) Soft

func (*CommandConfig) StreamExec

func (c *CommandConfig) StreamExec(name string, args ...string) ([]byte, error)

StreamExec executes a shell command with the specified name and arguments, using the CommandConfig configuration, and returns the output as a byte slice. StreamExec 使用 CommandConfig 的配置执行带有指定名称和参数的 shell 命令,并返回输出的字节切片。

func (*CommandConfig) SubConfig

func (c *CommandConfig) SubConfig(path string) *CommandConfig

SubConfig creates a shallow clone of the CommandConfig instance with a new path and returns the updated instance. SubConfig 创建一个带有新路径的 CommandConfig 实例的浅克隆并返回更新后的实例。

func (*CommandConfig) WithBash

func (c *CommandConfig) WithBash() *CommandConfig

WithBash sets the shell to bash with the "-c" flag and returns the updated instance. WithBash 设置 shell 为 bash 并附带 "-c" 参数,返回更新后的实例。

func (*CommandConfig) WithDebug

func (c *CommandConfig) WithDebug() *CommandConfig

WithDebug sets the debug mode to true and returns the updated instance WithDebug 将调试模式设置 true 并返回更新后的实例

func (*CommandConfig) WithDebugMode

func (c *CommandConfig) WithDebugMode(debugMode DebugMode) *CommandConfig

WithDebugMode sets the debug mode and returns the updated instance WithDebugMode 设置调试模式并返回更新后的实例

func (*CommandConfig) WithEnvs

func (c *CommandConfig) WithEnvs(envs []string) *CommandConfig

WithEnvs sets the environment variables and returns the updated instance WithEnvs 设置环境变量并返回更新后的实例

func (*CommandConfig) WithExpectCode

func (c *CommandConfig) WithExpectCode(exitCode int) *CommandConfig

WithExpectCode adds an expected exit code and returns the updated instance WithExpectCode 添加期望的退出码并返回更新后的实例

func (*CommandConfig) WithExpectExit

func (c *CommandConfig) WithExpectExit(exitCode int, reason string) *CommandConfig

WithExpectExit adds an expected exit code and returns the updated instance WithExpectExit 添加期望的退出码并返回更新后的实例

func (*CommandConfig) WithMatchMore

func (c *CommandConfig) WithMatchMore(matchMore bool) *CommandConfig

WithMatchMore sets the match more flag and returns the updated instance WithMatchMore 设置匹配更多标志并返回更新后的实例

func (*CommandConfig) WithMatchPipe

func (c *CommandConfig) WithMatchPipe(matchPipe func(outputLine string) bool) *CommandConfig

WithMatchPipe sets the match pipe function and returns the updated instance WithMatchPipe 设置匹配管道函数并返回更新后的实例

func (*CommandConfig) WithPath

func (c *CommandConfig) WithPath(path string) *CommandConfig

WithPath sets the execution path and returns the updated instance WithPath 设置执行路径并返回更新后的实例

func (*CommandConfig) WithSh

func (c *CommandConfig) WithSh() *CommandConfig

WithSh sets the shell to sh with the "-c" flag and returns the updated instance. WithSh 设置 shell 为 sh 并附带 "-c" 参数,返回更新后的实例。

func (*CommandConfig) WithShell

func (c *CommandConfig) WithShell(shellType, shellFlag string) *CommandConfig

WithShell sets both the shell type and shell flag, returns the updated instance WithShell 同时设置 shell 类型和 shell 参数,返回更新后的实例

func (*CommandConfig) WithShellFlag

func (c *CommandConfig) WithShellFlag(shellFlag string) *CommandConfig

WithShellFlag sets the shell flag and returns the updated instance WithShellFlag 设置 shell 参数并返回更新后的实例

func (*CommandConfig) WithShellType

func (c *CommandConfig) WithShellType(shellType string) *CommandConfig

WithShellType sets the shell type and returns the updated instance WithShellType 设置 shell 类型并返回更新后的实例

func (*CommandConfig) WithTakeExits

func (c *CommandConfig) WithTakeExits(takeExits map[int]string) *CommandConfig

WithTakeExits sets the accepted exit codes and returns the updated instance WithTakeExits 设置接受退出码集合并返回更新后的实例

func (*CommandConfig) WithZsh

func (c *CommandConfig) WithZsh() *CommandConfig

WithZsh sets the shell to zsh with the "-c" flag and returns the updated instance. WithZsh 设置 shell 为 zsh 并附带 "-c" 参数,返回更新后的实例。

type CommandConfig88Must

type CommandConfig88Must struct {
	// contains filtered or unexported fields
}

func (*CommandConfig88Must) Exec

func (T *CommandConfig88Must) Exec(name string, args ...string) (res []byte)

func (*CommandConfig88Must) ExecInPipe

func (T *CommandConfig88Must) ExecInPipe(name string, args ...string) (res []byte)

func (*CommandConfig88Must) ExecTake

func (T *CommandConfig88Must) ExecTake(name string, args ...string) (res []byte, res1 int)

func (*CommandConfig88Must) ExecWith

func (T *CommandConfig88Must) ExecWith(name string, args []string, prepare func(command *exec.Cmd)) (res []byte)

func (*CommandConfig88Must) IsShowCommand

func (T *CommandConfig88Must) IsShowCommand() (res bool)

func (*CommandConfig88Must) IsShowOutputs

func (T *CommandConfig88Must) IsShowOutputs() (res bool)

func (*CommandConfig88Must) NewConfig

func (T *CommandConfig88Must) NewConfig() (res *CommandConfig)

func (*CommandConfig88Must) StreamExec

func (T *CommandConfig88Must) StreamExec(name string, args ...string) (res []byte)

func (*CommandConfig88Must) SubConfig

func (T *CommandConfig88Must) SubConfig(path string) (res *CommandConfig)

func (*CommandConfig88Must) WithBash

func (T *CommandConfig88Must) WithBash() (res *CommandConfig)

func (*CommandConfig88Must) WithDebug

func (T *CommandConfig88Must) WithDebug() (res *CommandConfig)

func (*CommandConfig88Must) WithDebugMode

func (T *CommandConfig88Must) WithDebugMode(debugMode DebugMode) (res *CommandConfig)

func (*CommandConfig88Must) WithEnvs

func (T *CommandConfig88Must) WithEnvs(envs []string) (res *CommandConfig)

func (*CommandConfig88Must) WithExpectCode

func (T *CommandConfig88Must) WithExpectCode(exitCode int) (res *CommandConfig)

func (*CommandConfig88Must) WithExpectExit

func (T *CommandConfig88Must) WithExpectExit(exitCode int, reason string) (res *CommandConfig)

func (*CommandConfig88Must) WithMatchMore

func (T *CommandConfig88Must) WithMatchMore(matchMore bool) (res *CommandConfig)

func (*CommandConfig88Must) WithMatchPipe

func (T *CommandConfig88Must) WithMatchPipe(matchPipe func(outputLine string) bool) (res *CommandConfig)

func (*CommandConfig88Must) WithPath

func (T *CommandConfig88Must) WithPath(path string) (res *CommandConfig)

func (*CommandConfig88Must) WithSh

func (T *CommandConfig88Must) WithSh() (res *CommandConfig)

func (*CommandConfig88Must) WithShell

func (T *CommandConfig88Must) WithShell(shellType string, shellFlag string) (res *CommandConfig)

func (*CommandConfig88Must) WithShellFlag

func (T *CommandConfig88Must) WithShellFlag(shellFlag string) (res *CommandConfig)

func (*CommandConfig88Must) WithShellType

func (T *CommandConfig88Must) WithShellType(shellType string) (res *CommandConfig)

func (*CommandConfig88Must) WithTakeExits

func (T *CommandConfig88Must) WithTakeExits(takeExits map[int]string) (res *CommandConfig)

func (*CommandConfig88Must) WithZsh

func (T *CommandConfig88Must) WithZsh() (res *CommandConfig)

type CommandConfig88Omit

type CommandConfig88Omit struct {
	// contains filtered or unexported fields
}

func (*CommandConfig88Omit) Exec

func (T *CommandConfig88Omit) Exec(name string, args ...string) (res []byte)

func (*CommandConfig88Omit) ExecInPipe

func (T *CommandConfig88Omit) ExecInPipe(name string, args ...string) (res []byte)

func (*CommandConfig88Omit) ExecTake

func (T *CommandConfig88Omit) ExecTake(name string, args ...string) (res []byte, res1 int)

func (*CommandConfig88Omit) ExecWith

func (T *CommandConfig88Omit) ExecWith(name string, args []string, prepare func(command *exec.Cmd)) (res []byte)

func (*CommandConfig88Omit) IsShowCommand

func (T *CommandConfig88Omit) IsShowCommand() (res bool)

func (*CommandConfig88Omit) IsShowOutputs

func (T *CommandConfig88Omit) IsShowOutputs() (res bool)

func (*CommandConfig88Omit) NewConfig

func (T *CommandConfig88Omit) NewConfig() (res *CommandConfig)

func (*CommandConfig88Omit) StreamExec

func (T *CommandConfig88Omit) StreamExec(name string, args ...string) (res []byte)

func (*CommandConfig88Omit) SubConfig

func (T *CommandConfig88Omit) SubConfig(path string) (res *CommandConfig)

func (*CommandConfig88Omit) WithBash

func (T *CommandConfig88Omit) WithBash() (res *CommandConfig)

func (*CommandConfig88Omit) WithDebug

func (T *CommandConfig88Omit) WithDebug() (res *CommandConfig)

func (*CommandConfig88Omit) WithDebugMode

func (T *CommandConfig88Omit) WithDebugMode(debugMode DebugMode) (res *CommandConfig)

func (*CommandConfig88Omit) WithEnvs

func (T *CommandConfig88Omit) WithEnvs(envs []string) (res *CommandConfig)

func (*CommandConfig88Omit) WithExpectCode

func (T *CommandConfig88Omit) WithExpectCode(exitCode int) (res *CommandConfig)

func (*CommandConfig88Omit) WithExpectExit

func (T *CommandConfig88Omit) WithExpectExit(exitCode int, reason string) (res *CommandConfig)

func (*CommandConfig88Omit) WithMatchMore

func (T *CommandConfig88Omit) WithMatchMore(matchMore bool) (res *CommandConfig)

func (*CommandConfig88Omit) WithMatchPipe

func (T *CommandConfig88Omit) WithMatchPipe(matchPipe func(outputLine string) bool) (res *CommandConfig)

func (*CommandConfig88Omit) WithPath

func (T *CommandConfig88Omit) WithPath(path string) (res *CommandConfig)

func (*CommandConfig88Omit) WithSh

func (T *CommandConfig88Omit) WithSh() (res *CommandConfig)

func (*CommandConfig88Omit) WithShell

func (T *CommandConfig88Omit) WithShell(shellType string, shellFlag string) (res *CommandConfig)

func (*CommandConfig88Omit) WithShellFlag

func (T *CommandConfig88Omit) WithShellFlag(shellFlag string) (res *CommandConfig)

func (*CommandConfig88Omit) WithShellType

func (T *CommandConfig88Omit) WithShellType(shellType string) (res *CommandConfig)

func (*CommandConfig88Omit) WithTakeExits

func (T *CommandConfig88Omit) WithTakeExits(takeExits map[int]string) (res *CommandConfig)

func (*CommandConfig88Omit) WithZsh

func (T *CommandConfig88Omit) WithZsh() (res *CommandConfig)

type CommandConfig88Soft

type CommandConfig88Soft struct {
	// contains filtered or unexported fields
}

func (*CommandConfig88Soft) Exec

func (T *CommandConfig88Soft) Exec(name string, args ...string) (res []byte)

func (*CommandConfig88Soft) ExecInPipe

func (T *CommandConfig88Soft) ExecInPipe(name string, args ...string) (res []byte)

func (*CommandConfig88Soft) ExecTake

func (T *CommandConfig88Soft) ExecTake(name string, args ...string) (res []byte, res1 int)

func (*CommandConfig88Soft) ExecWith

func (T *CommandConfig88Soft) ExecWith(name string, args []string, prepare func(command *exec.Cmd)) (res []byte)

func (*CommandConfig88Soft) IsShowCommand

func (T *CommandConfig88Soft) IsShowCommand() (res bool)

func (*CommandConfig88Soft) IsShowOutputs

func (T *CommandConfig88Soft) IsShowOutputs() (res bool)

func (*CommandConfig88Soft) NewConfig

func (T *CommandConfig88Soft) NewConfig() (res *CommandConfig)

func (*CommandConfig88Soft) StreamExec

func (T *CommandConfig88Soft) StreamExec(name string, args ...string) (res []byte)

func (*CommandConfig88Soft) SubConfig

func (T *CommandConfig88Soft) SubConfig(path string) (res *CommandConfig)

func (*CommandConfig88Soft) WithBash

func (T *CommandConfig88Soft) WithBash() (res *CommandConfig)

func (*CommandConfig88Soft) WithDebug

func (T *CommandConfig88Soft) WithDebug() (res *CommandConfig)

func (*CommandConfig88Soft) WithDebugMode

func (T *CommandConfig88Soft) WithDebugMode(debugMode DebugMode) (res *CommandConfig)

func (*CommandConfig88Soft) WithEnvs

func (T *CommandConfig88Soft) WithEnvs(envs []string) (res *CommandConfig)

func (*CommandConfig88Soft) WithExpectCode

func (T *CommandConfig88Soft) WithExpectCode(exitCode int) (res *CommandConfig)

func (*CommandConfig88Soft) WithExpectExit

func (T *CommandConfig88Soft) WithExpectExit(exitCode int, reason string) (res *CommandConfig)

func (*CommandConfig88Soft) WithMatchMore

func (T *CommandConfig88Soft) WithMatchMore(matchMore bool) (res *CommandConfig)

func (*CommandConfig88Soft) WithMatchPipe

func (T *CommandConfig88Soft) WithMatchPipe(matchPipe func(outputLine string) bool) (res *CommandConfig)

func (*CommandConfig88Soft) WithPath

func (T *CommandConfig88Soft) WithPath(path string) (res *CommandConfig)

func (*CommandConfig88Soft) WithSh

func (T *CommandConfig88Soft) WithSh() (res *CommandConfig)

func (*CommandConfig88Soft) WithShell

func (T *CommandConfig88Soft) WithShell(shellType string, shellFlag string) (res *CommandConfig)

func (*CommandConfig88Soft) WithShellFlag

func (T *CommandConfig88Soft) WithShellFlag(shellFlag string) (res *CommandConfig)

func (*CommandConfig88Soft) WithShellType

func (T *CommandConfig88Soft) WithShellType(shellType string) (res *CommandConfig)

func (*CommandConfig88Soft) WithTakeExits

func (T *CommandConfig88Soft) WithTakeExits(takeExits map[int]string) (res *CommandConfig)

func (*CommandConfig88Soft) WithZsh

func (T *CommandConfig88Soft) WithZsh() (res *CommandConfig)

type DebugMode

type DebugMode string

DebugMode represents the debug output setting when executing commands DebugMode 表示执行命令时的调试输出设置

const (
	QUIET        DebugMode = "QUIET"        // Quiet mode with no debug output // 静默模式,无任何调试输出
	DEBUG        DebugMode = "DEBUG"        // Complete debug mode with detailed information // 完整调试模式,包含所有调试信息
	SHOW_COMMAND DebugMode = "SHOW_COMMAND" // Show command, not outputs // 显示命令,不显示输出
	SHOW_OUTPUTS DebugMode = "SHOW_OUTPUTS" // Show outputs, not command // 显示输出,不显示命令
)

func NewDebugMode

func NewDebugMode(debugModeOpen bool) DebugMode

NewDebugMode creates a DebugMode based on the debug mode flag. When debugModeOpen is true, returns DEBUG; otherwise, returns QUIET. NewDebugMode 根据调试模式标志创建 DebugMode。当 debugModeOpen 为 true 时,返回 DEBUG;否则返回 QUIET。

type ExecConfig

type ExecConfig = CommandConfig

ExecConfig is an alias representing CommandConfig ExecConfig 是 CommandConfig 的别名

func NewExecConfig

func NewExecConfig() *ExecConfig

NewExecConfig creates and returns a new ExecConfig instance NewExecConfig 创建并返回新的 ExecConfig 实例

Directories

Path Synopsis
internal
demos/demo1x command
demos/demo2x command
utils
Package utils provides utilities supporting command execution and output formatting
Package utils provides utilities supporting command execution and output formatting
Package osexectest provides testing utilities for command execution tests Contains functions to skip tests when commands are not available in PATH Logs command paths when commands are found on the system
Package osexectest provides testing utilities for command execution tests Contains functions to skip tests when commands are not available in PATH Logs command paths when commands are found on the system

Jump to

Keyboard shortcuts

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