Fix:(issue_1288). Add windows specific env format

This commit is contained in:
Naveen Gogineni 2022-10-18 19:53:02 -04:00
parent 5ac0710c11
commit da8868ffd9
2 changed files with 23 additions and 14 deletions

25
flag.go
View File

@ -6,7 +6,6 @@ import (
"fmt"
"io/ioutil"
"regexp"
"runtime"
"strings"
"syscall"
"time"
@ -268,21 +267,19 @@ func prefixedNames(names []string, placeholder string) string {
return prefixed
}
func withEnvHint(envVars []string, str string) string {
envText := ""
func envFormat(envVars []string, prefix, sep, suffix string) string {
if len(envVars) > 0 {
prefix := "$"
suffix := ""
sep := ", $"
if runtime.GOOS == "windows" {
prefix = "%"
suffix = "%"
sep = "%, %"
}
envText = fmt.Sprintf(" [%s%s%s]", prefix, strings.Join(envVars, sep), suffix)
return fmt.Sprintf(" [%s%s%s]", prefix, strings.Join(envVars, sep), suffix)
}
return str + envText
return ""
}
func defaultEnvFormat(envVars []string) string {
return envFormat(envVars, "$", ", $", "")
}
func withEnvHint(envVars []string, str string) string {
return str + defaultEnvFormat(envVars)
}
func FlagNames(name string, aliases []string) []string {

12
flag_windows.go Normal file
View File

@ -0,0 +1,12 @@
package cli
func withEnvHint(envVars []string, str string) string {
// if we are running is powershell this env var is set
// and so we should use the default env format
if os.Getenv("PSHOME") != "" {
envText = defaultEnvFormat(envVars)
} else {
envText = envFormat(envVars, "%", "%, %", "%")
}
return str + envText
}