cmdutil

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 19 Imported by: 3

README

Command Utilities

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanColor added in v0.0.5

func CleanColor(str string) string

func Exe added in v0.0.6

func Exe() string

Types

type CP

type CP struct {
}

CP todo

func (*CP) Copy

func (cp *CP) Copy(dst string, srcs ...string) error

type Chdir added in v0.0.3

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

Chdir 支持回退到之前目录的当前目录切换功能

func MustChdir added in v0.0.3

func MustChdir(to string) *Chdir

MustChdir 进入指定目录,若失败会 panic

func NewChdir added in v0.0.3

func NewChdir(to string) (*Chdir, error)

NewChdir 进入指定目录

func (*Chdir) GoBack added in v0.0.3

func (c *Chdir) GoBack() error

GoBack 回到初始目录

func (*Chdir) MustGoBack added in v0.0.3

func (c *Chdir) MustGoBack()

MustGoBack 回到初始目录,若失败会 panic

type DirPushd added in v0.0.3

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

DirPushd 类似 pushd、popd 命令的目录切换功能

func (*DirPushd) MustPopd added in v0.0.3

func (dp *DirPushd) MustPopd()

func (*DirPushd) MustPushd added in v0.0.3

func (dp *DirPushd) MustPushd(dir string)

func (*DirPushd) Popd added in v0.0.3

func (dp *DirPushd) Popd() error

Popd 返回前一个目录,若目录栈为空则直接返回 nil

func (*DirPushd) Pushd added in v0.0.3

func (dp *DirPushd) Pushd(dir string) error

Pushd 进入一个目录,并将当前目录入栈

type OSEnv

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

OSEnv 系统环境变量

func (*OSEnv) Append

func (oe *OSEnv) Append(key string, value string) error

Append 设置环境变量,若有相同的 key,则将 value 补充在最后

PATH = /home/work/bin:/opt/bin
Append("PATH","/home/root/bin")
--->
PATH =  /home/work/bin:/opt/bin:/home/root/bin

func (*OSEnv) Delete

func (oe *OSEnv) Delete(key string) error

Delete 删除指定 key 的环境变量

PATH =  /home/work/bin:/opt/bin
Delete("PATH")
Get("PATH")  ---> ""

func (*OSEnv) DeleteValue added in v0.0.6

func (oe *OSEnv) DeleteValue(key string, value string) error

DeleteValue 删除环境变量中 key 的 指定的值

PATH =  /home/work/bin:/opt/bin
DeleteValue("PATH","/opt/bin")
Get("PATH")  ---> "/home/work/bin"

func (*OSEnv) Environ

func (oe *OSEnv) Environ() []string

Environ 读取最终的环境变量信息

func (*OSEnv) Get

func (oe *OSEnv) Get(key string) string

Get 读取环境变量的值,若 key 不存在则返回空字符串

PATH =  /home/work/bin:/opt/bin
Get("PATH")  ---> "/home/work/bin:/opt/bin"

func (*OSEnv) GetValues added in v0.0.6

func (oe *OSEnv) GetValues(key string) []string

GetValues 读取环境变量的值,并采用 ListSeparator 分割

PATH =  /home/work/bin:/opt/bin
GetValues("PATH")  ---> ["/home/work/bin", "/opt/bin"]

func (*OSEnv) Insert

func (oe *OSEnv) Insert(key string, value string) error

Insert 设置环境变量,若有相同的 key,则将 value 插入到最前面

PATH = /home/work/bin:/opt/bin
Insert("PATH","/home/root/bin")
--->
PATH =  /home/root/bin:/home/work/bin:/opt/bin

func (*OSEnv) MustAppend added in v0.0.6

func (oe *OSEnv) MustAppend(key string, value string)

MustAppend Append 的别名,若有错误会 panic

func (*OSEnv) MustDelete added in v0.0.6

func (oe *OSEnv) MustDelete(key string)

MustDelete Delete 的别名,若有错误会 panic

func (*OSEnv) MustDeleteValue added in v0.0.6

func (oe *OSEnv) MustDeleteValue(key string, value string)

MustDeleteValue DeleteValue 的别名,若有错误会 panic

func (*OSEnv) MustInsert added in v0.0.6

func (oe *OSEnv) MustInsert(key string, value string)

MustInsert Insert 的别名,若有错误会 panic

func (*OSEnv) MustSet added in v0.0.6

func (oe *OSEnv) MustSet(key string, value string)

MustSet Set 的别名,若有错误会 panic

func (*OSEnv) Set

func (oe *OSEnv) Set(key string, value string) error

Set 设置环境变量,若有相同的 key,则整体覆盖掉

PATH = /home/work/bin:/opt/bin
Set("PATH","/home/root/bin")
--->
PATH = /home/root/bin

func (*OSEnv) TryAppend added in v0.0.6

func (oe *OSEnv) TryAppend(key string, value string)

TryAppend Append 的别名,忽略错误

func (*OSEnv) TryDelete added in v0.0.6

func (oe *OSEnv) TryDelete(key string)

TryDelete Delete 的别名,忽略错误

func (*OSEnv) TryDeleteValue added in v0.0.6

func (oe *OSEnv) TryDeleteValue(key string, value string)

TryDeleteValue DeleteValue 的别名,忽略错误

func (*OSEnv) TryInsert added in v0.0.6

func (oe *OSEnv) TryInsert(key string, value string)

TryInsert Insert 的别名,忽略错误

func (*OSEnv) TrySet added in v0.0.6

func (oe *OSEnv) TrySet(key string, value string)

TrySet Set 的别名,忽略错误

func (*OSEnv) WithEnviron

func (oe *OSEnv) WithEnviron(es []string)

WithEnviron 设置初始化的环境变量信息

若不调用该方法,会自动采用 os.Environ()作为默认值

type Tar

type Tar struct {
	// UnpackNextBefore 在 Unpack 时,解析到下一个 Header 后,实际 unpack 前的回调
	UnpackNextBefore func(h *tar.Header) (skip bool, err error)

	// UnpackNextAfter 在 Unpack 时,解析到下一个 Header 后,实际 unpack 后的回调
	UnpackNextAfter func(h *tar.Header, err error) error

	// UnCompress Unpack 时的解压缩方法,可选
	// 默认为按照文件后缀自动选择:
	// 1.后缀为 .gz 和 .tgz 时选择 gzip
	UnCompress func(rd io.Reader) (io.Reader, error)

	// StripComponents Unpack 的时候,忽略掉前 N 层目录
	StripComponents uint

	// MinSize 最小文件大小,>0 时有效
	MinSize int64

	// MaxSize 最小文件大小,>0 时有效
	MaxSize int64

	// IgnoreFailed 是否忽略异常
	// 不会忽略 UnpackNextBefore 返回的 error
	IgnoreFailed bool
}

Tar tape archive 工具,目前已经具备压缩文件

func (*Tar) Unpack

func (tr *Tar) Unpack(archiveFile string, targetDir string) error

Unpack 解压缩文件到指定目录

func (*Tar) UnpackFromReader

func (tr *Tar) UnpackFromReader(trd *tar.Reader, targetDir string) error

UnpackFromReader 从 tar.Reader 解压数据

type Wget

type Wget struct {
	// LogWriter 用于日志输出,可选
	LogWriter io.Writer

	// Proxy 代理配置,可选,当为 nil 时会使用 http.ProxyFromEnvironment
	Proxy func(*http.Request) (*url.URL, error)

	// Timeout 整体超时
	Timeout time.Duration

	// ConnectTimeout 连接超时,可选
	ConnectTimeout time.Duration

	// InsecureSkipVerify 是否跳过 tls 证书校验,可选
	InsecureSkipVerify bool
}

Wget 提供类似 wget 的功能

func (*Wget) Download

func (w *Wget) Download(src string, dst string) error

Download 从 src 这个地址下载到 dst 这个文件

func (*Wget) DownloadToWriter

func (w *Wget) DownloadToWriter(src string, dst io.Writer) error

DownloadToWriter 下载数据并写入指定的 writer

type WorkerGroup added in v0.0.5

type WorkerGroup struct {
	// Max 最大并发度,可选,默认为 1
	Max int
	// contains filtered or unexported fields
}

func (*WorkerGroup) Run added in v0.0.5

func (wg *WorkerGroup) Run(fn func())

func (*WorkerGroup) Wait added in v0.0.5

func (wg *WorkerGroup) Wait()

type Zip

type Zip struct {
	// UnpackNextBefore 在 Unpack 时,解析到下一个 Header 后,实际 unpack 前的回调
	UnpackNextBefore func(f *zip.File) (skip bool, err error)

	// UnpackNextAfter 在 Unpack 时,解析到下一个 Header 后,实际 unpack 后的回调
	UnpackNextAfter func(f *zip.File, err error) error

	// StripComponents Unpack 的时候,忽略掉前 N 层目录
	StripComponents uint

	// MinSize 最小文件大小,>0 时有效
	MinSize int64

	// MaxSize 最小文件大小,>0 时有效
	MaxSize int64

	// IgnoreFailed 是否忽略异常
	// 不会忽略 UnpackNextBefore 返回的 error
	IgnoreFailed bool
}

Zip 解压缩 .zip 文件

func (*Zip) Unpack

func (zp *Zip) Unpack(archiveFile string, targetDir string) error

Unpack 解压缩文件到指定目录

func (*Zip) UnpackFromReader

func (zp *Zip) UnpackFromReader(zrd *zip.Reader, targetDir string) error

UnpackFromReader 解压 zip.Reader

Directories

Path Synopsis
_example
Package gosdk 提供查找本机 go sdk 路径的功能
Package gosdk 提供查找本机 go sdk 路径的功能

Jump to

Keyboard shortcuts

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