1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-10 04:07:18 +02:00
lazygit/main.go

71 lines
1.5 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 (
"flag"
"fmt"
2018-08-09 04:25:32 +02:00
"io/ioutil"
"log"
"os"
"os/user"
2018-08-09 05:21:30 +02:00
"path/filepath"
"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-08 14:48:37 +02:00
commit string
version = "unversioned"
date string
2018-08-08 10:57:27 +02:00
2018-08-08 11:46:21 +02:00
debuggingFlag = flag.Bool("debug", false, "a boolean")
versionFlag = flag.Bool("v", false, "Print the current version")
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 {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
return usr.HomeDir
2018-06-05 11:32:03 +02:00
}
2018-08-09 05:29:25 +02:00
func projectPath(path string) string {
gopath := os.Getenv("GOPATH")
return filepath.FromSlash(gopath + "/src/github.com/jesseduffield/lazygit/" + path)
}
2018-08-09 04:25:32 +02: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 05:29:25 +02:00
path := projectPath("VERSION")
2018-08-09 05:21:30 +02:00
byteVersion, err := ioutil.ReadFile(path)
2018-08-09 04:25:32 +02:00
if err != nil {
return "unversioned"
2018-08-09 04:25:32 +02:00
}
return string(byteVersion)
}
2018-05-19 03:16:34 +02:00
func main() {
flag.Parse()
2018-08-09 04:25:32 +02:00
if version == "unversioned" {
version = fallbackVersion()
}
if *versionFlag {
2018-08-13 09:20:03 +02:00
fmt.Printf("commit=%s, build date=%s, version=%s\n", commit, date, version)
os.Exit(0)
}
appConfig := &config.AppConfig{
Name: "lazygit",
Version: version,
Commit: commit,
BuildDate: date,
Debug: *debuggingFlag,
}
app, err := app.NewApp(appConfig)
app.Log.Info(err)
app.GitCommand.SetupGit()
2018-08-12 13:04:47 +02:00
app.Gui.RunWithSubprocesses()
2018-05-19 03:16:34 +02:00
}