gex

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: Apache-2.0 Imports: 13 Imported by: 2

README

Gex

Sourcegraph GoDoc Go Report Card Build Status Codecov License

Golang exec extension library,Golang外部命令执行扩展库,有如下功能

  • 非常容易使用
  • 一切皆可配置
  • 可变参数
  • 运行时目录
  • 环境变量
  • 管道
  • 检查器
    • 字符串包含Contains
    • 字符串全包含ContainsAll
    • 字符串任何包含ContainsAny
    • 字符串相等Equal
    • 路径模式匹配PathMatch
    • 正则匹配Regexp
  • 通知器
    • 应用内方法通知Func
    • 其它通知器,通过额外代码库实现,不增加Gex的复杂度
  • 收集器
    • 字符串String
    • 文件File
    • 文件名Filename
    • 写入者Writer
  • 自动解决乱码

快速开始

Gex使用非常简单

package main

import (
  `github.com/goexl/gex`
)

func main() {
  _, _ = gex.Exec(`ping`, gex.Args(`www.163.com`, `-c`, 10))
}

or

package main

import (
  `github.com/goexl/gex`
)

func main() {
  _, _ = gex.Exec(`ping`, gex.Cli(`www.163.com -c 10`))
}

Gex有非常多的配置项,请参看使用文档

文档

点击这里查看最新文档

使用示例

点击这里查看最新的代码示例

交流

捐助

支持宝 微信

Documentation

Index

Constants

View Source
const (
	// WriteModeSkip 跳过
	WriteModeSkip writeMode = 1
	// WriteModeOverride 覆盖
	WriteModeOverride writeMode = 2
	// WriteModeError 返回错误
	WriteModeError writeMode = 3
	// WriteModeRename 重命名
	WriteModeRename writeMode = 4
	// WriteModeAppend 追加
	WriteModeAppend writeMode = 5
)

Variables

This section is empty.

Functions

func Args

func Args(args ...interface{}) *optionArgs

Args 配置命令运行的参数

func Async

func Async() *optionAsync

Async 配置异步执行

func Cache

func Cache() *optionCache

Cache 开启缓存

func Charset

func Charset(charset string) *optionCharset

Charset 配置流字符集

func Checker

func Checker(checker checker) *optionChecker

Checker 配置检查器

func Cli

func Cli(cli string) *optionArgs

Cli 使用命令行参数

func CollectAny

func CollectAny() *optionOutputType

CollectAny 收集所有流

func CollectCache

func CollectCache() *optionCollectorMode

CollectCache 缓存

func CollectDirect

func CollectDirect() *optionCollectorMode

CollectDirect 直接输出

func CollectStderr

func CollectStderr() *optionOutputType

CollectStderr 只收集错误流

func CollectStdout

func CollectStdout() *optionOutputType

CollectStdout 只收集输出流

func Collector

func Collector(collector collector) *optionCollector

Collector 配置输出

func ContainsAllChecker

func ContainsAllChecker(items []string, opts ...checkerOption) *optionChecker

ContainsAllChecker 字符串包含检查器

func ContainsAnyChecker

func ContainsAnyChecker(items []string, opts ...checkerOption) *optionChecker

ContainsAnyChecker 字符串包含检查器

func ContainsChecker

func ContainsChecker(contains string, opts ...checkerOption) *optionChecker

ContainsChecker 字符串包含检查器

func Context

func Context(context context.Context) *optionContext

Context 配置执行上下文

func Dir

func Dir(dir string) *optionDir

Dir 配置命令运行的目录

func DisablePwe

func DisablePwe() *optionPwe

DisablePwe 当出错时静默处理

func DisableSystemEnv added in v0.2.3

func DisableSystemEnv() *optionSystemEnv

DisableSystemEnv 关闭系统环境变量

func Env added in v0.2.2

func Env(key string, value string) *optionEnv

Env 环境变量

func EqualChecker

func EqualChecker(equal string, opts ...checkerOption) *optionChecker

EqualChecker 字符串全等检查器

func Exec

func Exec(command string, opts ...option) (code int, err error)

Exec 执行外部命令

func FileCollector

func FileCollector(file *os.File, opts ...collectorOption) *optionCollector

FileCollector 配置输出到文件

func FileStderr

func FileStderr(file *os.File) *optionStderr

FileStderr 文件输出

func FileStdin

func FileStdin(file *os.File) *optionStdin

FileStdin 文件输入

func FileStdout

func FileStdout(file *os.File) *optionStdout

FileStdout 文件输出

func FilenameCollector

func FilenameCollector(filename string, opts ...fileOption) (collector *optionCollector)

FilenameCollector 配置输出到文件

func FilenameStderr

func FilenameStderr(filename string, opts ...fileOption) (stderr *optionStderr)

FilenameStderr 文件名输出

func FilenameStdout

func FilenameStdout(filename string, opts ...fileOption) (stdout *optionStdout)

FilenameStdout 文件名输出

func FuncNotifier

func FuncNotifier(fun notifyFunc) *optionNotifier

FuncNotifier 应用内方法通知

func Max

func Max(max int) *optionMax

Max 配置最大收集行数

func NewOptions

func NewOptions(opts ...option) []option

NewOptions 快捷方法,因为接口不对外开放

func Notifier

func Notifier(notifier notifier) *optionNotifier

Notifier 配置检查器

func PathMatchChecker

func PathMatchChecker(pattern string, opts ...checkerOption) *optionChecker

PathMatchChecker 路径匹配检查器

func Pipe

func Pipe(name string, opts ...pipeOption) *optionPipe

Pipe 管道

func Pwe

func Pwe() *optionPwe

Pwe 当出错时打印信息到控制台

func Quiet

func Quiet() *optionQuiet

Quiet 配置清除终端显示

func ReaderStdin

func ReaderStdin(reader io.Reader) *optionStdin

ReaderStdin 读取者输入

func RegexpChecker

func RegexpChecker(regexp string, opts ...checkerOption) *optionChecker

RegexpChecker 正则表达式检查器

func Stderr

func Stderr(stderr io.Writer) *optionStderr

Stderr 配置标准错误流

func Stdout

func Stdout(stdout io.Writer) *optionStdout

Stdout 配置标准输出流

func StringCollector

func StringCollector(string *string, opts ...collectorOption) *optionCollector

StringCollector 配置输出到字符串

func StringEnv added in v0.2.2

func StringEnv(env string) *optionStringEnvs

StringEnv 环境变量

func StringEnvs added in v0.2.3

func StringEnvs(envs ...string) *optionStringEnvs

StringEnvs 环境变量列表

func Sync

func Sync() *optionAsync

Sync 配置同步执行

func Terminal

func Terminal() *optionTerminal

Terminal 配置终端显示

func WriteMode

func WriteMode(mode writeMode) *optionWriteMode

WriteMode 配置复制模式

func WriterCollector

func WriterCollector(writer io.Writer, opts ...collectorOption) *optionCollector

WriterCollector 配置输出到文件

Types

type CollectorMode

type CollectorMode uint8

CollectorMode 收集模式

const (
	// CollectorModeCache 缓存
	CollectorModeCache CollectorMode = 1
	// CollectorModeDirect 直接输出
	CollectorModeDirect CollectorMode = 2
)

type OutputType

type OutputType uint8

OutputType 输出类型

const (
	// OutputTypeStdout 输出流
	OutputTypeStdout OutputType = 1
	// OutputTypeStderr 错误流
	OutputTypeStderr OutputType = 2
	// OutputTypeAny 所有输出
	OutputTypeAny OutputType = 3
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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