yockc

package
v0.0.0-...-9853328 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	A_LAST    = 1
	A_STEP    = 2
	A_ROUND   = 4
	A_NO      = 8
	A_INVALID = 16
	A_ENUM    = 32
)
View Source
const (
	TermUndefined = iota
	TermPowershell
	TermCmd
	TermBash
)
View Source
const (
	UnsetExpandPosix = `#!/bin/bash
sed -i '/^export %s=%s/d' ~/.bashrc
. ~/.bashrc`
)

Variables

This section is empty.

Functions

func Alias

func Alias(k, v string)

func Cd

func Cd(dir string) error

Cd changes the current working directory to the named directory. If there is an error, it will be of type *PathError.

func Chmod

func Chmod(name string, mode int64) error

Chmod changes the mode of the named file to mode. If the file is a symbolic link, it changes the mode of the link's target. If there is an error, it will be of type *PathError.

A different subset of the mode bits are used, depending on the operating system.

On Unix, the mode's permission bits, ModeSetuid, ModeSetgid, and ModeSticky are used.

On Windows, only the 0200 bit (owner writable) of mode is used; it controls whether the file's read-only attribute is set or cleared. The other bits are currently unused. For compatibility with Go 1.12 and earlier, use a non-zero mode. Use mode 0400 for a read-only file and 0600 for a readable+writable file.

On Plan 9, the mode's permission bits, ModeAppend, ModeExclusive, and ModeTemporary are used.

func Chown

func Chown(name string, uid, gid int) error

Chown changes the numeric uid and gid of the named file. If the file is a symbolic link, it changes the uid and gid of the link's target. A uid or gid of -1 means to not change that value. If there is an error, it will be of type *PathError.

On Windows or Plan 9, Chown always returns the syscall.EWINDOWS or EPLAN9 error, wrapped in *PathError.

func Clear

func Clear() error

Clear clears the output on the screen

func Cp

func Cp(opt CpOpt, src, dst string) error

func CronParse

func CronParse(str string) (expr cronExpr, command string)

func CrontabAdd

func CrontabAdd(expr string, names ...string) error

func CrontabDel

func CrontabDel(expr string, names ...string) error

func Curl

func Curl(opt CurlOpt, urls []string) ([]byte, error)

Curl is similar with curl, which is used to send Curl request according to opt and urls.

func Echo

func Echo(opt EchoOpt, str string) (string, error)

Echo prints str to the screen and returns str. Similar to GNU's echo, you can also print environment variables by $GOPATH

func Environ

func Environ(k string) string

func Exec

func Exec(opt ExecOpt, cmd string) (string, error)

func Export

func Export(opt ExportOpt, k, v string) error

func ExportL

func ExportL(k, v string) error

func Find

func Find(opt FindOpt, path string) ([]string, error)

func IPTablesListDarwin

func IPTablesListDarwin(str string) (rules []fireWareRuleDarwin, err error)

func IPTablesListLinux

func IPTablesListLinux(str string) (rules []fireWareRuleLinux, err error)

func IPTablesListWindows

func IPTablesListWindows(str string) (rules []firewareRuleWindows, err error)

func IPTablesOp

func IPTablesOp(opt IPTablesOpOpt) error

func KillByName

func KillByName(name string) error

func KillByPid

func KillByPid(pid int32) error

func MultiScript

func MultiScript(name, s string) (string, error)

func Mv

func Mv(opt MvOpt, src, dst string) error

func Nohup

func Nohup(cmds string) error

func OnceScript

func OnceScript(s string) (string, error)

func PS

func PS(opt PSOpt) (info map[int32]*ProcessInfo, err error)

func Rename

func Rename(old, new string)

func Rm

func Rm(opt RmOpt, target string) error

func SystemCtlCreate

func SystemCtlCreate(name string, opt SCCreateOpt) error

func SystemCtlDelete

func SystemCtlDelete(server string) error

func SystemCtlDisable

func SystemCtlDisable(server string) error

func SystemCtlIsEnable

func SystemCtlIsEnable(name string) bool

func SystemCtlRelaod

func SystemCtlRelaod(server string) error

func SystemCtlStart

func SystemCtlStart(server string) error

func SystemCtlStop

func SystemCtlStop(server string) error

func Tar

func Tar(src, dst string) error

func Unalias

func Unalias(k string)

func Unset

func Unset(opt UnsetOpt, k, v string) error

func UnsetL

func UnsetL(k string) error

func Untar

func Untar(src, dst string) error

func Unzip

func Unzip(src, dst string) error

func Whereis

func Whereis(path string) (string, error)

func Zip

func Zip(src, dst string) error

Types

type ArgsBuilder

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

func NewArgsBuilder

func NewArgsBuilder(cmds ...string) *ArgsBuilder

func (*ArgsBuilder) Add

func (builder *ArgsBuilder) Add(cmds ...string) *ArgsBuilder

func (*ArgsBuilder) AddInt

func (builder *ArgsBuilder) AddInt(k string, i int) *ArgsBuilder

func (*ArgsBuilder) AddString

func (builder *ArgsBuilder) AddString(k string, v string) *ArgsBuilder

func (*ArgsBuilder) Build

func (builder *ArgsBuilder) Build() string

func (*ArgsBuilder) MustAddString

func (builder *ArgsBuilder) MustAddString()

type CpOpt

type CpOpt struct {
	Recurse bool
	Force   bool
}

CpOpt indicates configuration of cp

type CronTask

type CronTask interface {
	Expr() string
	Cmd() string
}

func CrontabList

func CrontabList(expr string) (tasks []CronTask, err error)

type CurlOpt

type CurlOpt struct {
	// Header contains the request header fields either received
	// by the server or to be sent by the client.
	Header map[string]string
	// Method specifies the HTTP method (GET, POST, PUT, etc.).
	Method string
	Data   string
	Cookie *http.Cookie
	// Save will write body into specified file
	Save bool
	// Dir set root directory of file to be saved
	Dir string
	// FilenameHandle returns filename that will be saved according to url
	FilenameHandle func(string) string
	// Strict will exit at once when error occur
	Strict bool

	// Async will enable goroutines when it's true.
	//
	// maxRequestCount and wg to limit count of concurrent goroutines
	Async bool
	// contains filtered or unexported fields
}

CurlOpt indicates configuration of HTTP request

type EchoOpt

type EchoOpt struct {
	Fd   []string
	Mode string
}

type ExecOpt

type ExecOpt struct {
	// Redirect set stdout, stderr, stdin stream
	Redirect bool
	Quiet    bool

	Sandbox bool

	Terminal uint8
}

ExecOpt indicates configuration of exec

type ExportOpt

type ExportOpt struct {
	Expand bool
	System bool
}

type FindOpt

type FindOpt struct {
	Search  bool
	Pattern string
	Case    bool
	Dir     bool
	File    bool
}

type FireWareRule

type FireWareRule interface {
	Name() string
	Proto() string
	Src() string
	Dst() string
	Action() string
}

func IPTablesList

func IPTablesList(opt IPTablesListOpt) (rules []FireWareRule, err error)

type IPTablesListOpt

type IPTablesListOpt struct {
	Legacy bool
	Chain  string
	Name   string
}

type IPTablesOpOpt

type IPTablesOpOpt struct {
	Chain       string `json:"chain"`
	Name        string `json:"name"`
	Protocol    string `json:"protocol"`
	Destination string `json:"dest"`
	// linux: ACCEPT, DROP, REJECT, LOG, SNAT, DNAT, MASQUEREAD
	Action string          `json:"action"`
	Legacy bool            `json:"legacy"`
	Op     IPTablesOperate `json:"op"`
}

func (IPTablesOpOpt) ToLinux

func (opt IPTablesOpOpt) ToLinux() string

func (IPTablesOpOpt) ToWindows

func (opt IPTablesOpOpt) ToWindows() string

type IPTablesOperate

type IPTablesOperate byte
const (
	IPTablesAdd IPTablesOperate
	IPTablesDel
)

type LsFileInfo

type LsFileInfo struct {
	Perm     string
	Size     int64
	ModTime  string
	Filename string
}

func Ls

func Ls(opt LsOpt) ([]LsFileInfo, error)

type LsOpt

type LsOpt struct {
	Dir string

	Callack func(path string, info fs.FileInfo) bool
	// contains filtered or unexported fields
}

func (*LsOpt) SetRecurse

func (opt *LsOpt) SetRecurse()

type LsofInfo

type LsofInfo struct {
	Protocal string `json:"protocal"`
	Local    string `json:"local"`
	Foreign  string `json:"foregin"`
	State    string `json:"state"`
	Pid      int32  `json:"pid"`
}
Example
test.Batch(test.BatchOpt{
	Path: "./testdata/lsof/linux",
}).Range(func(data string) error {
	fmt.Println(lsofLinux(data))
	return nil
})
Output:

[{tcp 0.0.0.0:22 0.0.0.0:* LISTEN 0} {tcp 127.0.0.1:631 0.0.0.0:* LISTEN 0} {tcp 127.0.0.53:53 0.0.0.0:* LISTEN 0} {tcp6 :::8080 :::* LISTEN 2717}]

func Lsof

func Lsof() ([]LsofInfo, error)

type MvOpt

type MvOpt struct{}

MvOpt indicates configuration of mv

type PGrepResult

type PGrepResult struct {
	Pid  int32
	Name string
}

func PGrep

func PGrep(name string) []PGrepResult

type PSOpt

type PSOpt struct {
	User bool
	CPU  bool
	Mem  bool
	Time bool

	String bool
}

type ProcessInfo

type ProcessInfo struct {
	Name  string
	User  string
	CPU   float64
	Cmd   string
	Mem   *process.MemoryInfoStat
	Start int64
}

type RmOpt

type RmOpt struct {
	Safe    bool
	Recurse bool
	// Pattern delete file to be matched
	Pattern string
}

RmOpt indicates configuration of rm

type SCCreateOpt

type SCCreateOpt struct {
	Unit    scCreateOptUnit    `json:"unit"`
	Service scCreateOptService `json:"service"`
	Install scCreateOptInstall `json:"install"`
}

func (*SCCreateOpt) String

func (s *SCCreateOpt) String() string

type SSHCenter

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

SSHCenter manages the SSHClient

type SSHClient

type SSHClient struct {
	*ssh.Client
}

SSHClient packs the SSH connection

func NewSSHClient

func NewSSHClient(opt SSHOpt) (*SSHClient, error)

func (*SSHClient) Exec

func (cli *SSHClient) Exec(cmd string) (string, error)

Exec creates a temporary session to execute commands

func (*SSHClient) Get

func (cli *SSHClient) Get(src, dst string) error

Get download remote file to localhost from remote server

func (*SSHClient) OS

func (cli *SSHClient) OS() string

func (*SSHClient) Put

func (cli *SSHClient) Put(src, dst string) error

Put uploads local files to a remote server

func (*SSHClient) Sh

func (cli *SSHClient) Sh(file string, args ...string) (string, error)

func (*SSHClient) Shell

func (cli *SSHClient) Shell() error

Shell assigns a terminal to the user while redrecting stdout, stderr, stdin. Input exit to release the terminal to close the session.

type SSHOpt

type SSHOpt struct {
	User string
	// password
	Pwd  string
	IP   string
	Port int
	// tcp, udp, etc.
	Network  string
	Redirect bool
}

SSHOpt indicates configuration of newSSHClient

type SSHReader

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

SSHReader implements io.Reader, which reads string stream by channel.

func NewSSHReader

func NewSSHReader() *SSHReader

func (*SSHReader) Read

func (r *SSHReader) Read(p []byte) (n int, err error)

type SSHWriter

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

SSHWriter implements io.Writer, which writes to a string stream by channel.

func NewSSHWriter

func NewSSHWriter() *SSHWriter

func (*SSHWriter) Write

func (w *SSHWriter) Write(p []byte) (n int, err error)

type ServiceInfo

type ServiceInfo interface {
	PID() int32
	Name() string
	Status() string
}

func SystemCtlStatus

func SystemCtlStatus(opt SystemCtlStatusOpt) (infos []ServiceInfo, err error)

type SystemCtlStatusOpt

type SystemCtlStatusOpt struct {
	Type   string `json:"type"`
	Status string `json:"status"`
	Name   string `json:"name"`
}

type Terminal

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

Terminal is a struct to abstract different termnial

func PosixTerm

func PosixTerm(cmds ...string) *Terminal

func WindowsTerm

func WindowsTerm(cmds ...string) *Terminal

func (*Terminal) AppendCmds

func (term *Terminal) AppendCmds(cmds ...string)

func (*Terminal) Clear

func (term *Terminal) Clear()

func (*Terminal) Exec

func (term *Terminal) Exec(opt *ExecOpt) ([]byte, error)

func (*Terminal) SetCmds

func (term *Terminal) SetCmds(cmds ...string)

func (*Terminal) Type

func (term *Terminal) Type() uint8

type UnsetOpt

type UnsetOpt struct {
	Expand bool
	System bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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