Skip to content

Commit

Permalink
Merge pull request #1538 from dearchap/issue_1288
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap authored Oct 22, 2022
2 parents d1ac284 + 96bff3c commit 8ea10b8
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"io/ioutil"
"os"
"regexp"
"runtime"
"strings"
Expand Down Expand Up @@ -268,19 +269,23 @@ 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 = "%, %"
}
return fmt.Sprintf(" [%s%s%s]", prefix, strings.Join(envVars, sep), suffix)
}
return ""
}

envText = fmt.Sprintf(" [%s%s%s]", prefix, strings.Join(envVars, sep), suffix)
func defaultEnvFormat(envVars []string) string {
return envFormat(envVars, "$", ", $", "")
}

func withEnvHint(envVars []string, str string) string {
envText := ""
if runtime.GOOS != "windows" || os.Getenv("PSHOME") != "" {
envText = defaultEnvFormat(envVars)
} else {
envText = envFormat(envVars, "%", "%, %", "%")
}
return str + envText
}
Expand Down

0 comments on commit 8ea10b8

Please sign in to comment.