diff options
author | Glenn Vriesman <glenn.vriesman@gmail.com> | 2019-09-24 18:52:46 +0200 |
---|---|---|
committer | Glenn Vriesman <glenn.vriesman@gmail.com> | 2019-09-24 18:52:46 +0200 |
commit | 431f1aa766e3f633e12e2c32ceabb62540378032 (patch) | |
tree | 7ab209e1fd066264642b123f5a7c82b7f2da525c /main.go | |
parent | 379dcf0972d55cb16f3d58cd475988ca2a9c5915 (diff) |
Main: Added directory argument
* Added a positional argument that allows the user to change the dir
Signed-off-by: Glenn Vriesman <glenn.vriesman@gmail.com>
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 36 |
1 files changed, 27 insertions, 9 deletions
@@ -1,7 +1,6 @@ package main import ( - "flag" "fmt" "log" "os" @@ -9,6 +8,7 @@ import ( "runtime" "github.com/go-errors/errors" + "github.com/integrii/flaggy" "github.com/jesseduffield/lazygit/pkg/app" "github.com/jesseduffield/lazygit/pkg/config" ) @@ -18,10 +18,6 @@ var ( version = "unversioned" date string buildSource = "unknown" - - configFlag = flag.Bool("config", false, "Print the current default config") - debuggingFlag = flag.Bool("debug", false, "a boolean") - versionFlag = flag.Bool("v", false, "Print the current version") ) func projectPath(path string) string { @@ -30,17 +26,39 @@ func projectPath(path string) string { } func main() { - flag.Parse() - if *versionFlag { + flaggy.DefaultParser.ShowVersionWithVersionFlag = false + + repoPath := "." + flaggy.AddPositionalValue(&repoPath, "path", 1, false, "Path of git repo") + + 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 + flaggy.Bool(&configFlag, "c", "config", "Print the current default config") + + flaggy.Parse() + + if versionFlag { 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 { + if configFlag { fmt.Printf("%s\n", config.GetDefaultConfig()) os.Exit(0) } - appConfig, err := config.NewAppConfig("lazygit", version, commit, date, buildSource, *debuggingFlag) + + if repoPath != "." { + if err := os.Chdir(repoPath); err != nil { + log.Fatal(err.Error()) + } + } + + appConfig, err := config.NewAppConfig("lazygit", version, commit, date, buildSource, debuggingFlag) if err != nil { log.Fatal(err.Error()) } |