1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00
lazygit/main.go

66 lines
1.6 KiB
Go
Raw Normal View History

2018-05-19 11:16:34 +10:00
package main
2018-06-02 08:35:49 +10:00
import (
"flag"
"fmt"
2018-08-09 12:25:32 +10:00
"io/ioutil"
"os"
2018-08-09 13:21:30 +10:00
"path/filepath"
"runtime"
"github.com/jesseduffield/lazygit/pkg/app"
"github.com/jesseduffield/lazygit/pkg/config"
2018-06-02 08:35:49 +10:00
)
2018-06-05 19:30:55 +10:00
var (
2018-08-08 22:48:37 +10:00
commit string
version = "unversioned"
date string
2018-08-08 18:57:27 +10:00
2018-08-08 19:46:21 +10:00
debuggingFlag = flag.Bool("debug", false, "a boolean")
versionFlag = flag.Bool("v", false, "Print the current version")
2018-06-05 19:30:55 +10:00
)
2018-05-27 16:32:09 +10:00
2018-08-09 13:29:25 +10:00
func projectPath(path string) string {
gopath := os.Getenv("GOPATH")
return filepath.FromSlash(gopath + "/src/github.com/jesseduffield/lazygit/" + path)
}
2018-08-09 12:25:32 +10:00
// when building the binary, `version` is set as a compile-time variable, along
// with `date` and `commit`. If this program has been opened directly via go,
// we will populate the `version` with VERSION in the lazygit root directory
func fallbackVersion() string {
2018-08-09 13:29:25 +10:00
path := projectPath("VERSION")
2018-08-09 13:21:30 +10:00
byteVersion, err := ioutil.ReadFile(path)
2018-08-09 12:25:32 +10:00
if err != nil {
return "unversioned"
2018-08-09 12:25:32 +10:00
}
return string(byteVersion)
}
2018-05-19 11:16:34 +10:00
func main() {
flag.Parse()
2018-08-09 12:25:32 +10:00
if version == "unversioned" {
version = fallbackVersion()
}
if *versionFlag {
fmt.Printf("commit=%s, build date=%s, version=%s, os=%s, arch=%s\n", commit, date, version, runtime.GOOS, runtime.GOARCH)
os.Exit(0)
}
2018-08-15 21:34:25 +10:00
appConfig, err := config.NewAppConfig("lazygit", version, commit, date, debuggingFlag)
if err != nil {
panic(err)
}
2018-08-15 21:34:25 +10:00
app, err := app.NewApp(appConfig)
2018-08-18 19:43:58 +10:00
if err != nil {
// TODO: remove this call to panic after anonymous error reporting
// is setup (right now the call to panic logs nothing to the screen which
// would make debugging difficult
panic(err)
// app.Log.Panic(err.Error())
}
app.GitCommand.SetupGit()
2018-08-12 21:04:47 +10:00
app.Gui.RunWithSubprocesses()
2018-05-19 11:16:34 +10:00
}