Documentation ¶
Index ¶
- func CopyDir(src string, dst string) (err error)
- func CopyFile(src, dst string) (err error)
- func Kill(cmd *exec.Cmd) error
- func RunCommandWithOutputLiveAux(c *OSCommand, cmdObj ICmdObj, writer io.Writer, ...) error
- func RunCommandWithOutputLiveWrapper(c *OSCommand, cmdObj ICmdObj, writer io.Writer, output func(string) string) error
- func RunLineOutputCmd(cmd *exec.Cmd, onLine func(line string) (bool, error)) error
- type CmdLogEntry
- type CmdObj
- type ICmdObj
- type OSCommand
- func (c *OSCommand) AppendLineToFile(filename, line string) error
- func (c *OSCommand) CopyToClipboard(str string) error
- func (c *OSCommand) CreateFileWithContent(path string, content string) error
- func (c *OSCommand) CreateTempFile(filename, content string) (string, error)
- func (c *OSCommand) DetectUnamePass(cmdObj ICmdObj, writer io.Writer, promptUserForCredential func(string) string) error
- func (c *OSCommand) ExecutableFromString(commandStr string) *exec.Cmd
- func (c *OSCommand) FileExists(path string) (bool, error)
- func (c *OSCommand) FileType(path string) string
- func (c *OSCommand) GetLazygitPath() string
- func (c *OSCommand) LogCommand(cmdStr string, commandLine bool)
- func (c *OSCommand) LogExecCmd(cmd *exec.Cmd)
- func (c *OSCommand) NewCmdObj(cmd *exec.Cmd) ICmdObj
- func (c *OSCommand) NewCmdObjFromArgs(args []string) ICmdObj
- func (c *OSCommand) NewCmdObjFromStr(cmdStr string) ICmdObj
- func (c *OSCommand) OpenFile(filename string) error
- func (c *OSCommand) OpenLink(link string) error
- func (c *OSCommand) PipeCommands(commandStrings ...string) error
- func (c *OSCommand) PrepareShellSubProcess(command string) *exec.Cmd
- func (c *OSCommand) PrepareSubProcess(cmdName string, commandArgs ...string) *exec.Cmd
- func (c *OSCommand) Quote(message string) string
- func (c *OSCommand) Remove(filename string) error
- func (c *OSCommand) RemoveFile(path string) error
- func (c *OSCommand) RunCommand(formatString string, formatArgs ...interface{}) error
- func (c *OSCommand) RunCommandWithOptions(command string, options RunCommandOptions) error
- func (c *OSCommand) RunCommandWithOutput(formatString string, formatArgs ...interface{}) (string, error)
- func (c *OSCommand) RunCommandWithOutputLive(cmdObj ICmdObj, writer io.Writer, handleOutput func(string) string) error
- func (c *OSCommand) RunCommandWithOutputWithOptions(command string, options RunCommandOptions) (string, error)
- func (c *OSCommand) RunExecutable(cmd *exec.Cmd) error
- func (c *OSCommand) RunExecutableWithOutput(cmd *exec.Cmd) (string, error)
- func (c *OSCommand) RunPreparedCommand(cmd *exec.Cmd) error
- func (c *OSCommand) RunShellCommand(command string) error
- func (c *OSCommand) SetBeforeExecuteCmd(cmd func(*exec.Cmd))
- func (c *OSCommand) SetCommand(cmd func(string, ...string) *exec.Cmd)
- func (c *OSCommand) SetOnRunCommand(f func(CmdLogEntry))
- func (c *OSCommand) SetRemoveFile(f func(string) error)
- func (c *OSCommand) ShellCommandFromString(commandStr string) *exec.Cmd
- func (c *OSCommand) WithSpan(span string) *OSCommand
- type Platform
- type RunCommandOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyDir ¶
CopyDir recursively copies a directory tree, attempting to preserve permissions. Source directory must exist. If destination already exists we'll clobber it. Symlinks are ignored and skipped.
func CopyFile ¶
CopyFile copies the contents of the file named src to the file named by dst. The file will be created if it does not already exist. If the destination file exists, all it's contents will be replaced by the contents of the source file. The file mode will be copied from the source and the copied data is synced/flushed to stable storage.
func RunCommandWithOutputLiveAux ¶ added in v0.31.1
func RunCommandWithOutputLiveAux( c *OSCommand, cmdObj ICmdObj, writer io.Writer, handleOutput func(string) string, startCmd func(cmd *exec.Cmd) (*cmdHandler, error), ) error
RunCommandWithOutputLiveAux runs a command and return every word that gets written in stdout Output is a function that executes by every word that gets read by bufio As return of output you need to give a string that will be written to stdin NOTE: If the return data is empty it won't write anything to stdin
Types ¶
type CmdLogEntry ¶ added in v0.28.1
type CmdLogEntry struct {
// contains filtered or unexported fields
}
TODO: make these fields private
func NewCmdLogEntry ¶ added in v0.28.1
func NewCmdLogEntry(cmdStr string, span string, commandLine bool) CmdLogEntry
func (CmdLogEntry) GetCmdStr ¶ added in v0.28.1
func (e CmdLogEntry) GetCmdStr() string
func (CmdLogEntry) GetCommandLine ¶ added in v0.28.1
func (e CmdLogEntry) GetCommandLine() bool
func (CmdLogEntry) GetSpan ¶ added in v0.28.1
func (e CmdLogEntry) GetSpan() string
type CmdObj ¶ added in v0.30.1
type CmdObj struct {
// contains filtered or unexported fields
}
func (*CmdObj) AddEnvVars ¶ added in v0.30.1
type ICmdObj ¶ added in v0.30.1
A command object is a general way to represent a command to be run on the command line. If you want to log the command you'll use .ToString() and if you want to run it you'll use .GetCmd()
type OSCommand ¶
type OSCommand struct { Log *logrus.Entry Platform *Platform Config config.AppConfigurer Command func(string, ...string) *exec.Cmd BeforeExecuteCmd func(*exec.Cmd) Getenv func(string) string // something like 'Staging File': allows us to group cmd logs under a single title CmdLogSpan string // contains filtered or unexported fields }
OSCommand holds all the os commands
func NewDummyOSCommand ¶
func NewDummyOSCommand() *OSCommand
NewDummyOSCommand creates a new dummy OSCommand for testing
func NewOSCommand ¶
func NewOSCommand(log *logrus.Entry, config config.AppConfigurer) *OSCommand
NewOSCommand os command runner
func (*OSCommand) AppendLineToFile ¶
AppendLineToFile adds a new line in file
func (*OSCommand) CopyToClipboard ¶
func (*OSCommand) CreateFileWithContent ¶
CreateFileWithContent creates a file with the given content
func (*OSCommand) CreateTempFile ¶
CreateTempFile writes a string to a new temp file and returns the file's name
func (*OSCommand) DetectUnamePass ¶
func (c *OSCommand) DetectUnamePass(cmdObj ICmdObj, writer io.Writer, promptUserForCredential func(string) string) error
DetectUnamePass detect a username / password / passphrase question in a command promptUserForCredential is a function that gets executed when this function detect you need to fillin a password or passphrase The promptUserForCredential argument will be "username", "password" or "passphrase" and expects the user's password/passphrase or username back
func (*OSCommand) ExecutableFromString ¶
ExecutableFromString takes a string like `git status` and returns an executable command for it
func (*OSCommand) FileExists ¶
FileExists checks whether a file exists at the specified path
func (*OSCommand) GetLazygitPath ¶
GetLazygitPath returns the path of the currently executed file
func (*OSCommand) LogCommand ¶ added in v0.28.1
func (*OSCommand) LogExecCmd ¶ added in v0.28.1
func (*OSCommand) NewCmdObjFromArgs ¶ added in v0.30.1
func (*OSCommand) NewCmdObjFromStr ¶ added in v0.30.1
func (*OSCommand) PipeCommands ¶
PipeCommands runs a heap of commands and pipes their inputs/outputs together like A | B | C
func (*OSCommand) PrepareShellSubProcess ¶ added in v0.27.1
PrepareShellSubProcess returns the pointer to a custom command
func (*OSCommand) PrepareSubProcess ¶
PrepareSubProcess iniPrepareSubProcessrocess then tells the Gui to switch to it TODO: see if this needs to exist, given that ExecutableFromString does the same things
func (*OSCommand) RemoveFile ¶ added in v0.28.1
func (*OSCommand) RunCommand ¶
RunCommand runs a command and just returns the error
func (*OSCommand) RunCommandWithOptions ¶
func (c *OSCommand) RunCommandWithOptions(command string, options RunCommandOptions) error
func (*OSCommand) RunCommandWithOutput ¶
func (c *OSCommand) RunCommandWithOutput(formatString string, formatArgs ...interface{}) (string, error)
RunCommandWithOutput wrapper around commands returning their output and error NOTE: If you don't pass any formatArgs we'll just use the command directly, however there's a bizarre compiler error/warning when you pass in a formatString with a percent sign because it thinks it's supposed to be a formatString when in that case it's not. To get around that error you'll need to define the string in a variable and pass the variable into RunCommandWithOutput.
func (*OSCommand) RunCommandWithOutputLive ¶
func (c *OSCommand) RunCommandWithOutputLive(cmdObj ICmdObj, writer io.Writer, handleOutput func(string) string) error
Due to a lack of pty support on windows we have RunCommandWithOutputLiveWrapper being defined separate for windows and other OS's
func (*OSCommand) RunCommandWithOutputWithOptions ¶
func (c *OSCommand) RunCommandWithOutputWithOptions(command string, options RunCommandOptions) (string, error)
func (*OSCommand) RunExecutable ¶
RunExecutable runs an executable file and returns an error if there was one
func (*OSCommand) RunExecutableWithOutput ¶
RunExecutableWithOutput runs an executable file and returns its output
func (*OSCommand) RunPreparedCommand ¶
RunPreparedCommand takes a pointer to an exec.Cmd and runs it this is useful if you need to give your command some environment variables before running it
func (*OSCommand) RunShellCommand ¶ added in v0.27.1
RunShellCommand runs shell commands i.e. 'sh -c <command>'. Good for when you need access to the shell
func (*OSCommand) SetBeforeExecuteCmd ¶
func (*OSCommand) SetCommand ¶
SetCommand sets the command function used by the struct. To be used for testing only
func (*OSCommand) SetOnRunCommand ¶ added in v0.28.1
func (c *OSCommand) SetOnRunCommand(f func(CmdLogEntry))
func (*OSCommand) SetRemoveFile ¶ added in v0.28.1
To be used for testing only
func (*OSCommand) ShellCommandFromString ¶
ShellCommandFromString takes a string like `git commit` and returns an executable shell command for it
type Platform ¶
type Platform struct { OS string Shell string ShellArg string OpenCommand string OpenLinkCommand string }
Platform stores the os state
type RunCommandOptions ¶
type RunCommandOptions struct {
EnvVars []string
}