feat(cli): use gitconfig name as name prompt default value

This commit is contained in:
hi019
2021-03-25 11:07:15 -04:00
committed by Lea Anthony
parent eb7349efbc
commit 779095c988
2 changed files with 11 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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")
}