From 779095c9880a9fc7627b532ab23c4a3826eaa018 Mon Sep 17 00:00:00 2001 From: hi019 <65871571+hi019@users.noreply.github.com> Date: Thu, 25 Mar 2021 11:07:15 -0400 Subject: [PATCH] feat(cli): use gitconfig name as name prompt default value --- cmd/helpers.go | 6 ++++++ cmd/system.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/cmd/helpers.go b/cmd/helpers.go index 6b93b456..d7a65fae 100644 --- a/cmd/helpers.go +++ b/cmd/helpers.go @@ -595,3 +595,9 @@ func ldFlags(po *ProjectOptions, buildMode string) string { } return ldflags } + +func getGitConfigValue(key string) (string, error) { + output, err := exec.Command("git", "config", "--get", "--null", key).Output() + // When using --null git appends a null character (\u0000) to the command output + return strings.TrimRight(string(output), "\u0000"), err +} diff --git a/cmd/system.go b/cmd/system.go index 55cd1bca..ddf8ffdb 100644 --- a/cmd/system.go +++ b/cmd/system.go @@ -99,11 +99,16 @@ func (s *SystemHelper) setup() error { if config.Name != "" { systemConfig["name"] = PromptRequired("What is your name", config.Name) + } else if n, err := getGitConfigValue("user.name"); err == nil && n != "" { + systemConfig["name"] = PromptRequired("What is your name", n) } else { systemConfig["name"] = PromptRequired("What is your name") } + if config.Email != "" { systemConfig["email"] = PromptRequired("What is your email address", config.Email) + } else if e, err := getGitConfigValue("user.email"); err == nil && e != "" { + systemConfig["email"] = PromptRequired("What is your email address", e) } else { systemConfig["email"] = PromptRequired("What is your email address") }