2018-05-19 03:16:34 +02:00
|
|
|
package main
|
|
|
|
|
2018-06-02 00:35:49 +02:00
|
|
|
import (
|
2018-07-21 07:51:18 +02:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/user"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/fatih/color"
|
2018-06-02 00:35:49 +02:00
|
|
|
)
|
|
|
|
|
2018-06-05 11:30:55 +02:00
|
|
|
var (
|
2018-07-21 07:51:18 +02:00
|
|
|
startTime time.Time
|
|
|
|
debugging bool
|
2018-06-05 11:30:55 +02:00
|
|
|
)
|
2018-05-27 08:32:09 +02:00
|
|
|
|
2018-06-05 11:32:03 +02:00
|
|
|
func homeDirectory() string {
|
2018-07-21 07:51:18 +02:00
|
|
|
usr, err := user.Current()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
return usr.HomeDir
|
2018-06-05 11:32:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func devLog(objects ...interface{}) {
|
2018-07-21 07:51:18 +02:00
|
|
|
localLog(color.FgWhite, homeDirectory()+"/go/src/github.com/jesseduffield/lazygit/development.log", objects...)
|
2018-06-05 11:32:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func colorLog(colour color.Attribute, objects ...interface{}) {
|
2018-07-21 07:51:18 +02:00
|
|
|
localLog(colour, homeDirectory()+"/go/src/github.com/jesseduffield/lazygit/development.log", objects...)
|
2018-06-05 11:32:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func commandLog(objects ...interface{}) {
|
2018-07-21 07:51:18 +02:00
|
|
|
localLog(color.FgWhite, homeDirectory()+"/go/src/github.com/jesseduffield/lazygit/commands.log", objects...)
|
2018-06-05 11:32:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func localLog(colour color.Attribute, path string, objects ...interface{}) {
|
2018-07-21 07:51:18 +02:00
|
|
|
if !debugging {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
f, _ := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644)
|
|
|
|
defer f.Close()
|
|
|
|
for _, object := range objects {
|
|
|
|
colorFunction := color.New(colour).SprintFunc()
|
|
|
|
f.WriteString(colorFunction(fmt.Sprint(object)) + "\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func navigateToRepoRootDirectory() {
|
|
|
|
_, err := os.Stat(".git")
|
|
|
|
for os.IsNotExist(err) {
|
|
|
|
devLog("going up a directory to find the root")
|
|
|
|
os.Chdir("..")
|
|
|
|
_, err = os.Stat(".git")
|
|
|
|
}
|
2018-06-05 11:32:03 +02:00
|
|
|
}
|
|
|
|
|
2018-05-19 03:16:34 +02:00
|
|
|
func main() {
|
2018-07-21 07:51:18 +02:00
|
|
|
debuggingPointer := flag.Bool("debug", false, "a boolean")
|
|
|
|
flag.Parse()
|
|
|
|
debugging = *debuggingPointer
|
|
|
|
devLog("\n\n\n\n\n\n\n\n\n\n")
|
|
|
|
startTime = time.Now()
|
|
|
|
verifyInGitRepo()
|
|
|
|
navigateToRepoRootDirectory()
|
|
|
|
run()
|
2018-05-19 03:16:34 +02:00
|
|
|
}
|