Documentation ¶
Index ¶
- func CopyDir(src string, dst string) (err error)
- func CopyFile(src, dst string) (err error)
- func FileType(path string) string
- func GetLazygitPath() string
- func GetTempDir() string
- func Kill(cmd *exec.Cmd) error
- func NewGuiIO(log *logrus.Entry, logCommandFn func(string, bool), ...) *guiIO
- func NewNullGuiIO(log *logrus.Entry) *guiIO
- func TestOSCommandOpenFileDarwin(t *testing.T)
- func TestOSCommandOpenFileLinux(t *testing.T)
- type CmdObj
- func (self *CmdObj) AddEnvVars(vars ...string) ICmdObj
- func (self *CmdObj) DontLog() ICmdObj
- func (self *CmdObj) FailOnCredentialRequest() ICmdObj
- func (self *CmdObj) GetCmd() *exec.Cmd
- func (self *CmdObj) GetCredentialStrategy() CredentialStrategy
- func (self *CmdObj) GetEnvVars() []string
- func (self *CmdObj) PromptOnCredentialRequest() ICmdObj
- func (self *CmdObj) Run() error
- func (self *CmdObj) RunAndProcessLines(onLine func(line string) (bool, error)) error
- func (self *CmdObj) RunWithOutput() (string, error)
- func (self *CmdObj) ShouldLog() bool
- func (self *CmdObj) ToString() string
- type CmdObjBuilder
- func (self *CmdObjBuilder) CloneWithNewRunner(decorate func(ICmdObjRunner) ICmdObjRunner) *CmdObjBuilder
- func (self *CmdObjBuilder) New(cmdStr string) ICmdObj
- func (self *CmdObjBuilder) NewFromArgs(args []string) ICmdObj
- func (self *CmdObjBuilder) NewShell(commandStr string) ICmdObj
- func (self *CmdObjBuilder) Quote(message string) string
- type CredentialStrategy
- type CredentialType
- type FakeCmdObjRunner
- func (self *FakeCmdObjRunner) CheckForMissingCalls()
- func (self *FakeCmdObjRunner) Expect(expectedCmdStr string, output string, err error) *FakeCmdObjRunner
- func (self *FakeCmdObjRunner) ExpectArgs(expectedArgs []string, output string, err error) *FakeCmdObjRunner
- func (self *FakeCmdObjRunner) ExpectFunc(fn func(cmdObj ICmdObj) (string, error)) *FakeCmdObjRunner
- func (self *FakeCmdObjRunner) ExpectGitArgs(expectedArgs []string, output string, err error) *FakeCmdObjRunner
- func (self *FakeCmdObjRunner) Run(cmdObj ICmdObj) error
- func (self *FakeCmdObjRunner) RunAndProcessLines(cmdObj ICmdObj, onLine func(line string) (bool, error)) error
- func (self *FakeCmdObjRunner) RunWithOutput(cmdObj ICmdObj) (string, error)
- type ICmdObj
- type ICmdObjBuilder
- type ICmdObjRunner
- 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) FileExists(path string) (bool, error)
- func (c *OSCommand) Getenv(key string) string
- func (c *OSCommand) LogCommand(cmdStr string, commandLine bool)
- func (c *OSCommand) OpenFile(filename string) error
- func (c *OSCommand) OpenLink(link string) error
- func (c *OSCommand) PipeCommands(commandStrings ...string) error
- func (c *OSCommand) Quote(message string) string
- func (c *OSCommand) Remove(filename string) error
- func (c *OSCommand) RemoveFile(path string) error
- type OSCommandDeps
- type Platform
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 GetLazygitPath ¶ added in v0.32.1
func GetLazygitPath() string
GetLazygitPath returns the path of the currently executed file
func GetTempDir ¶ added in v0.32.1
func GetTempDir() string
func NewNullGuiIO ¶ added in v0.32.1
we use this function when we want to access the functionality of our OS struct but we don't have anywhere to log things, or request input from the user.
func TestOSCommandOpenFileDarwin ¶ added in v0.32.1
func TestOSCommandOpenFileLinux ¶ added in v0.32.1
TestOSCommandOpenFileLinux tests the OpenFile command on Linux
Types ¶
type CmdObj ¶ added in v0.30.1
type CmdObj struct {
// contains filtered or unexported fields
}
func (*CmdObj) AddEnvVars ¶ added in v0.30.1
func (*CmdObj) FailOnCredentialRequest ¶ added in v0.32.1
func (*CmdObj) GetCredentialStrategy ¶ added in v0.32.1
func (self *CmdObj) GetCredentialStrategy() CredentialStrategy
func (*CmdObj) GetEnvVars ¶ added in v0.32.1
func (*CmdObj) PromptOnCredentialRequest ¶ added in v0.32.1
func (*CmdObj) RunAndProcessLines ¶ added in v0.32.1
func (*CmdObj) RunWithOutput ¶ added in v0.32.1
type CmdObjBuilder ¶ added in v0.32.1
type CmdObjBuilder struct {
// contains filtered or unexported fields
}
func NewDummyCmdObjBuilder ¶ added in v0.32.1
func NewDummyCmdObjBuilder(runner ICmdObjRunner) *CmdObjBuilder
func (*CmdObjBuilder) CloneWithNewRunner ¶ added in v0.32.1
func (self *CmdObjBuilder) CloneWithNewRunner(decorate func(ICmdObjRunner) ICmdObjRunner) *CmdObjBuilder
func (*CmdObjBuilder) New ¶ added in v0.32.1
func (self *CmdObjBuilder) New(cmdStr string) ICmdObj
func (*CmdObjBuilder) NewFromArgs ¶ added in v0.32.1
func (self *CmdObjBuilder) NewFromArgs(args []string) ICmdObj
func (*CmdObjBuilder) NewShell ¶ added in v0.32.1
func (self *CmdObjBuilder) NewShell(commandStr string) ICmdObj
func (*CmdObjBuilder) Quote ¶ added in v0.32.1
func (self *CmdObjBuilder) Quote(message string) string
type CredentialStrategy ¶ added in v0.32.1
type CredentialStrategy int
const ( // do not expect a credential request. If we end up getting one // we'll be in trouble because the command will hang indefinitely NONE CredentialStrategy = iota // expect a credential request and if we get one, prompt the user to enter their username/password PROMPT // in this case we will check for a credential request (i.e. the command pauses to ask for // username/password) and if we get one, we just submit a newline, forcing the // command to fail. We use this e.g. for a background `git fetch` to prevent it // from hanging indefinitely. FAIL )
type CredentialType ¶ added in v0.32.1
type CredentialType int
const ( Password CredentialType = iota Username Passphrase )
type FakeCmdObjRunner ¶ added in v0.32.1
type FakeCmdObjRunner struct {
// contains filtered or unexported fields
}
func NewFakeRunner ¶ added in v0.32.1
func NewFakeRunner(t *testing.T) *FakeCmdObjRunner
func (*FakeCmdObjRunner) CheckForMissingCalls ¶ added in v0.32.1
func (self *FakeCmdObjRunner) CheckForMissingCalls()
func (*FakeCmdObjRunner) Expect ¶ added in v0.32.1
func (self *FakeCmdObjRunner) Expect(expectedCmdStr string, output string, err error) *FakeCmdObjRunner
func (*FakeCmdObjRunner) ExpectArgs ¶ added in v0.32.1
func (self *FakeCmdObjRunner) ExpectArgs(expectedArgs []string, output string, err error) *FakeCmdObjRunner
func (*FakeCmdObjRunner) ExpectFunc ¶ added in v0.32.1
func (self *FakeCmdObjRunner) ExpectFunc(fn func(cmdObj ICmdObj) (string, error)) *FakeCmdObjRunner
func (*FakeCmdObjRunner) ExpectGitArgs ¶ added in v0.32.1
func (self *FakeCmdObjRunner) ExpectGitArgs(expectedArgs []string, output string, err error) *FakeCmdObjRunner
func (*FakeCmdObjRunner) Run ¶ added in v0.32.1
func (self *FakeCmdObjRunner) Run(cmdObj ICmdObj) error
func (*FakeCmdObjRunner) RunAndProcessLines ¶ added in v0.32.1
func (*FakeCmdObjRunner) RunWithOutput ¶ added in v0.32.1
func (self *FakeCmdObjRunner) RunWithOutput(cmdObj ICmdObj) (string, error)
type ICmdObj ¶ added in v0.30.1
type ICmdObj interface { GetCmd() *exec.Cmd // outputs string representation of command. Note that if the command was built // using NewFromArgs, the output won't be quite the same as what you would type // into a terminal e.g. 'sh -c git commit' as opposed to 'sh -c "git commit"' ToString() string AddEnvVars(...string) ICmdObj GetEnvVars() []string // runs the command and returns an error if any Run() error // runs the command and returns the output as a string, and an error if any RunWithOutput() (string, error) // runs the command and runs a callback function on each line of the output. If the callback returns true for the boolean value, we kill the process and return. RunAndProcessLines(onLine func(line string) (bool, error)) error // Be calling DontLog(), we're saying that once we call Run(), we don't want to // log the command in the UI (it'll still be logged in the log file). The general rule // is that if a command doesn't change the git state (e.g. read commands like `git diff`) // then we don't want to log it. If we are changing something (e.g. `git add .`) then // we do. The only exception is if we're running a command in the background periodically // like `git fetch`, which technically does mutate stuff but isn't something we need // to notify the user about. DontLog() ICmdObj // This returns false if DontLog() was called ShouldLog() bool PromptOnCredentialRequest() ICmdObj FailOnCredentialRequest() ICmdObj GetCredentialStrategy() CredentialStrategy }
A command object is a general way to represent a command to be run on the command line.
type ICmdObjBuilder ¶ added in v0.32.1
type ICmdObjBuilder interface { // New returns a new command object based on the string provided New(cmdStr string) ICmdObj // NewShell takes a string like `git commit` and returns an executable shell command for it e.g. `sh -c 'git commit'` NewShell(commandStr string) ICmdObj // NewFromArgs takes a slice of strings like []string{"git", "commit"} and returns a new command object. This can be useful when you don't want to worry about whitespace and quoting and stuff. NewFromArgs(args []string) ICmdObj // Quote wraps a string in quotes with any necessary escaping applied. The reason for bundling this up with the other methods in this interface is that we basically always need to make use of this when creating new command objects. Quote(str string) string }
type ICmdObjRunner ¶ added in v0.32.1
type OSCommand ¶
type OSCommand struct { *common.Common Platform *Platform Cmd *CmdObjBuilder // 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 NewDummyOSCommandWithDeps ¶ added in v0.32.1
func NewDummyOSCommandWithDeps(deps OSCommandDeps) *OSCommand
func NewDummyOSCommandWithRunner ¶ added in v0.32.1
func NewDummyOSCommandWithRunner(runner *FakeCmdObjRunner) *OSCommand
func NewOSCommand ¶
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) FileExists ¶
FileExists checks whether a file exists at the specified path
func (*OSCommand) LogCommand ¶ added in v0.28.1
func (*OSCommand) PipeCommands ¶
PipeCommands runs a heap of commands and pipes their inputs/outputs together like A | B | C