mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
simplify how we log commands
This commit is contained in:
@ -22,16 +22,20 @@ type ICmdObj interface {
|
||||
// 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
|
||||
|
||||
// logs command
|
||||
Log() ICmdObj
|
||||
// Marks the command object as readonly, so that when it is run, we don't log it to the user.
|
||||
// We only want to log commands to the user which change state in some way.
|
||||
DontLog() ICmdObj
|
||||
ShouldLog() bool
|
||||
}
|
||||
|
||||
type CmdObj struct {
|
||||
cmdStr string
|
||||
cmd *exec.Cmd
|
||||
|
||||
runner ICmdObjRunner
|
||||
logCommand func(ICmdObj)
|
||||
runner ICmdObjRunner
|
||||
|
||||
// if set to true, we don't want to log the command to the user.
|
||||
dontLog bool
|
||||
}
|
||||
|
||||
func (self *CmdObj) GetCmd() *exec.Cmd {
|
||||
@ -52,12 +56,15 @@ func (self *CmdObj) GetEnvVars() []string {
|
||||
return self.cmd.Env
|
||||
}
|
||||
|
||||
func (self *CmdObj) Log() ICmdObj {
|
||||
self.logCommand(self)
|
||||
|
||||
func (self *CmdObj) DontLog() ICmdObj {
|
||||
self.dontLog = true
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *CmdObj) ShouldLog() bool {
|
||||
return !self.dontLog
|
||||
}
|
||||
|
||||
func (self *CmdObj) Run() error {
|
||||
return self.runner.Run(self)
|
||||
}
|
||||
|
Reference in New Issue
Block a user