From 0d2076c57c217768133a932f579e7a8e687392d1 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 5 Jun 2018 19:30:55 +1000 Subject: [PATCH] generalised logs --- gitcommands.go | 23 ++++++++++++++++++----- main.go | 14 +++++++++++--- status_panel.go | 2 +- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/gitcommands.go b/gitcommands.go index 622d10d1e..ba6de342e 100644 --- a/gitcommands.go +++ b/gitcommands.go @@ -5,8 +5,10 @@ import ( // "log" "errors" "fmt" + "log" "os" "os/exec" + "os/user" "strings" "time" @@ -48,19 +50,30 @@ type StashEntry struct { DisplayString string } +func homeDirectory() string { + usr, err := user.Current() + if err != nil { + log.Fatal(err) + } + return usr.HomeDir +} + func devLog(objects ...interface{}) { - localLog(color.FgWhite, "/Users/jesseduffieldduffield/go/src/github.com/jesseduffield/gitgot/development.log", objects...) + localLog(color.FgWhite, homeDirectory()+"/go/src/github.com/jesseduffield/lazygit/development.log", objects...) } func colorLog(colour color.Attribute, objects ...interface{}) { - localLog(colour, "/Users/jesseduffieldduffield/go/src/github.com/jesseduffield/gitgot/development.log", objects...) + localLog(colour, homeDirectory()+"/go/src/github.com/jesseduffield/lazygit/development.log", objects...) } func commandLog(objects ...interface{}) { - localLog(color.FgWhite, "/Users/jesseduffieldduffield/go/src/github.com/jesseduffield/gitgot/commands.log", objects...) + localLog(color.FgWhite, homeDirectory()+"/go/src/github.com/jesseduffield/lazygit/commands.log", objects...) } func localLog(colour color.Attribute, path string, objects ...interface{}) { + if !debugging { + return + } f, _ := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644) defer f.Close() for _, object := range objects { @@ -263,11 +276,11 @@ func gitCheckout(branch string, force bool) (string, error) { } func runCommand(command string) (string, error) { - startTime := time.Now() + commandStartTime := time.Now() commandLog(command) splitCmd := strings.Split(command, " ") cmdOut, err := exec.Command(splitCmd[0], splitCmd[1:]...).CombinedOutput() - devLog("run command time: ", time.Now().Sub(startTime)) + devLog("run command time: ", time.Now().Sub(commandStartTime)) return string(cmdOut), err } diff --git a/main.go b/main.go index 66f9686b3..1ca5357da 100644 --- a/main.go +++ b/main.go @@ -1,15 +1,23 @@ package main import ( + "flag" + "fmt" "time" ) -// StartTime : The starting time of the app -var StartTime time.Time +var ( + startTime time.Time + debugging bool +) func main() { + debuggingPointer := flag.Bool("debug", false, "a boolean") + flag.Parse() + debugging = *debuggingPointer + fmt.Println(homeDirectory() + "/go/src/github.com/jesseduffield/lazygit/development.log") devLog("\n\n\n\n\n\n\n\n\n\n") - StartTime = time.Now() + startTime = time.Now() verifyInGitRepo() run() } diff --git a/status_panel.go b/status_panel.go index 2f40e2a62..fded5995d 100644 --- a/status_panel.go +++ b/status_panel.go @@ -28,7 +28,7 @@ func refreshStatus(g *gocui.Gui) error { // utilising the fact these all have padding to only grab the name // from the display string with the existing coloring applied fmt.Fprint(v, " "+branch.DisplayString[4:]) - colorLog(color.FgCyan, time.Now().Sub(StartTime)) + colorLog(color.FgCyan, time.Now().Sub(startTime)) return nil })