1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-28 09:08:41 +02:00
lazygit/main.go

92 lines
2.2 KiB
Go
Raw Normal View History

2018-05-19 03:16:34 +02:00
package main
2018-06-02 00:35:49 +02:00
import (
"fmt"
"log"
"os"
"runtime"
"github.com/go-errors/errors"
"github.com/integrii/flaggy"
"github.com/jesseduffield/lazygit/pkg/app"
"github.com/jesseduffield/lazygit/pkg/config"
2018-06-02 00:35:49 +02:00
)
2018-06-05 11:30:55 +02:00
var (
2018-08-25 07:55:49 +02:00
commit string
version = "unversioned"
date string
buildSource = "unknown"
2018-06-05 11:30:55 +02:00
)
2018-05-27 08:32:09 +02:00
2018-05-19 03:16:34 +02:00
func main() {
flaggy.DefaultParser.ShowVersionWithVersionFlag = false
repoPath := "."
flaggy.String(&repoPath, "p", "path", "Path of git repo")
2020-03-29 01:11:15 +02:00
filterPath := ""
flaggy.String(&filterPath, "f", "filter", "Path to filter on in `git log -- <path>`. When in filter mode, the commits, reflog, and stash are filtered based on the given path, and some operations are restricted")
dump := ""
flaggy.AddPositionalValue(&dump, "gitargs", 1, false, "Todo file")
flaggy.DefaultParser.PositionalFlags[0].Hidden = true
versionFlag := false
flaggy.Bool(&versionFlag, "v", "version", "Print the current version")
debuggingFlag := false
flaggy.Bool(&debuggingFlag, "d", "debug", "Run in debug mode with logging")
configFlag := false
2020-09-18 00:39:16 +02:00
flaggy.Bool(&configFlag, "c", "config", "Print the default config")
logFlag := false
flaggy.Bool(&logFlag, "l", "logs", "Tail lazygit logs (intended to be used in a separate terminal tab to lazygit)")
flaggy.Parse()
if versionFlag {
2018-08-25 07:55:49 +02:00
fmt.Printf("commit=%s, build date=%s, build source=%s, version=%s, os=%s, arch=%s\n", commit, date, buildSource, version, runtime.GOOS, runtime.GOARCH)
os.Exit(0)
}
if configFlag {
2018-08-26 10:42:25 +02:00
fmt.Printf("%s\n", config.GetDefaultConfig())
os.Exit(0)
}
if logFlag {
app.TailLogs()
os.Exit(0)
}
if repoPath != "." {
if err := os.Chdir(repoPath); err != nil {
log.Fatal(err.Error())
}
}
appConfig, err := config.NewAppConfig("lazygit", version, commit, date, buildSource, debuggingFlag)
2018-08-15 13:34:25 +02:00
if err != nil {
log.Fatal(err.Error())
}
2018-08-15 13:34:25 +02:00
2020-03-29 01:11:15 +02:00
app, err := app.NewApp(appConfig, filterPath)
if err == nil {
err = app.Run()
2018-08-18 11:43:58 +02:00
}
if err != nil {
if errorMessage, known := app.KnownError(err); known {
log.Fatal(errorMessage)
}
newErr := errors.Wrap(err, 0)
stackTrace := newErr.ErrorStack()
app.Log.Error(stackTrace)
log.Fatal(fmt.Sprintf("%s\n\n%s", app.Tr.SLocalize("ErrorOccurred"), stackTrace))
}
2018-05-19 03:16:34 +02:00
}