osutil

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const EscapeRune = '\\'

Variables

This section is empty.

Functions

func ExecName

func ExecName(name string) string

func FilepathClean added in v1.1.0

func FilepathClean(s string) string

func FilepathHasDirPrefix

func FilepathHasDirPrefix(s, prefix string) bool

func FilepathSplitAt

func FilepathSplitAt(s string, n int) string

Result does not start with separator.

func FsCaseFilename added in v1.3.3

func FsCaseFilename(filename string) (string, error)

func GetEnv added in v1.1.0

func GetEnv(env []string, key string) string

func GetFreeTcpPort added in v1.1.0

func GetFreeTcpPort() (int, error)

func HomeEnvVar

func HomeEnvVar() string

func KillExecCmd

func KillExecCmd(cmd *exec.Cmd) error

func OpenBrowser added in v1.1.0

func OpenBrowser(url string) error

doesn't wait for the cmd to end

func OpenFilemanager added in v1.1.0

func OpenFilemanager(filename string) error

doesn't wait for the cmd to end

func OpenTerminal added in v1.3.1

func OpenTerminal(filename string) error

doesn't wait for the cmd to end

func RandomPort added in v1.1.0

func RandomPort(simpleSeed, min, max int) int

func RunCmdCombinedOutput added in v1.1.0

func RunCmdCombinedOutput(cmd *Cmd, rd io.Reader) ([]byte, error)

func RunCmdI added in v1.3.3

func RunCmdI(ci CmdI) error

func RunCmdOutputs added in v1.1.0

func RunCmdOutputs(cmd *Cmd, rd io.Reader) (sout []byte, serr []byte, _ error)

func RunCmdStdoutAndStderrInErr added in v1.1.0

func RunCmdStdoutAndStderrInErr(cmd *Cmd, rd io.Reader) ([]byte, error)

Adds stderr to err if it happens.

func SetEnv added in v1.1.0

func SetEnv(env []string, key, value string) []string

func SetEnvs added in v1.1.0

func SetEnvs(env []string, addEnv []string) []string

func SetupExecCmdSysProcAttr

func SetupExecCmdSysProcAttr(cmd *exec.Cmd)

func ShellRunArgs

func ShellRunArgs(args ...string) []string

func UnquoteEnvValues added in v1.3.1

func UnquoteEnvValues(env []string) []string

Types

type BasicCmd added in v1.3.3

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

func NewBasicCmd added in v1.3.3

func NewBasicCmd(cmd *exec.Cmd) *BasicCmd

func (*BasicCmd) Cmd added in v1.3.3

func (c *BasicCmd) Cmd() *exec.Cmd

func (*BasicCmd) Start added in v1.3.3

func (c *BasicCmd) Start() error

func (*BasicCmd) Wait added in v1.3.3

func (c *BasicCmd) Wait() error

type CallbackOnStartCmd added in v1.3.3

type CallbackOnStartCmd struct {
	CmdI
	// contains filtered or unexported fields
}

ex: usefull to print something before any cmd output is printed

func NewCallbackOnStartCmd added in v1.3.3

func NewCallbackOnStartCmd(cmdi CmdI, cb func(CmdI)) *CallbackOnStartCmd

func (*CallbackOnStartCmd) Start added in v1.3.3

func (c *CallbackOnStartCmd) Start() error

func (*CallbackOnStartCmd) Wait added in v1.3.3

func (c *CallbackOnStartCmd) Wait() error

type Cmd added in v1.1.0

type Cmd struct {
	*exec.Cmd

	PreOutputCallback func()

	NoEnsureStop bool
	// contains filtered or unexported fields
}

func NewCmd added in v1.1.0

func NewCmd(ctx context.Context, args ...string) *Cmd

If Start() is not called, Cancel() must be called to clear resources.

func (*Cmd) Cancel added in v1.1.0

func (cmd *Cmd) Cancel()

can be called before a Start(), clears all possible resources

func (*Cmd) Run added in v1.1.0

func (cmd *Cmd) Run() error

func (*Cmd) SetupStdio added in v1.1.0

func (cmd *Cmd) SetupStdio(ir io.Reader, ow, ew io.Writer) error

func (*Cmd) Start added in v1.1.0

func (cmd *Cmd) Start() error

If Start() returns no error, Wait() must be called to clear resources.

func (*Cmd) Wait added in v1.1.0

func (cmd *Cmd) Wait() error

type CmdI added in v1.3.3

type CmdI interface {
	Cmd() *exec.Cmd
	Start() error
	Wait() error
}

func NewCmdI added in v1.3.3

func NewCmdI(cmd *exec.Cmd) CmdI

type SetSidCmd added in v1.3.3

type SetSidCmd struct {
	CmdI
	// contains filtered or unexported fields
}

func NewSetSidCmd added in v1.3.3

func NewSetSidCmd(ctx context.Context, cmdi CmdI) *SetSidCmd

func (*SetSidCmd) Start added in v1.3.3

func (c *SetSidCmd) Start() error

func (*SetSidCmd) Wait added in v1.3.3

func (c *SetSidCmd) Wait() error

type ShellCmd added in v1.3.3

type ShellCmd struct {
	CmdI
}

func NewShellCmd added in v1.3.3

func NewShellCmd(cmdi CmdI) *ShellCmd

type TmpFiles

type TmpFiles struct {
	Dir string
}

func NewTmpFiles

func NewTmpFiles(prefix string) *TmpFiles

func (*TmpFiles) MkdirInTmp

func (tf *TmpFiles) MkdirInTmp(path string) (string, error)

func (*TmpFiles) MkdirInTmpOrPanic

func (tf *TmpFiles) MkdirInTmpOrPanic(path string) string

Returns the filename

func (*TmpFiles) RemoveAll

func (tf *TmpFiles) RemoveAll() error

func (*TmpFiles) WriteFileInTmp

func (tf *TmpFiles) WriteFileInTmp(path string, src []byte) (string, error)

func (*TmpFiles) WriteFileInTmp2OrPanic

func (tf *TmpFiles) WriteFileInTmp2OrPanic(path string, src string) string

Returns the filename

func (*TmpFiles) WriteFileInTmpOrPanic

func (tf *TmpFiles) WriteFileInTmpOrPanic(path string, src []byte) string

Returns the filename

Jump to

Keyboard shortcuts

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