Merge pull request #1538 from dearchap/issue_1288

This commit is contained in:
dearchap 2022-10-22 15:51:14 -04:00 committed by GitHub
commit 8ea10b85ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

27
flag.go
View File

@ -5,6 +5,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"regexp" "regexp"
"runtime" "runtime"
"strings" "strings"
@ -268,19 +269,23 @@ func prefixedNames(names []string, placeholder string) string {
return prefixed return prefixed
} }
func envFormat(envVars []string, prefix, sep, suffix string) string {
if len(envVars) > 0 {
return fmt.Sprintf(" [%s%s%s]", prefix, strings.Join(envVars, sep), suffix)
}
return ""
}
func defaultEnvFormat(envVars []string) string {
return envFormat(envVars, "$", ", $", "")
}
func withEnvHint(envVars []string, str string) string { func withEnvHint(envVars []string, str string) string {
envText := "" envText := ""
if len(envVars) > 0 { if runtime.GOOS != "windows" || os.Getenv("PSHOME") != "" {
prefix := "$" envText = defaultEnvFormat(envVars)
suffix := "" } else {
sep := ", $" envText = envFormat(envVars, "%", "%, %", "%")
if runtime.GOOS == "windows" {
prefix = "%"
suffix = "%"
sep = "%, %"
}
envText = fmt.Sprintf(" [%s%s%s]", prefix, strings.Join(envVars, sep), suffix)
} }
return str + envText return str + envText
} }