Fix:(issue_1288). Add windows specific env format
This commit is contained in:
parent
5ac0710c11
commit
da8868ffd9
25
flag.go
25
flag.go
@ -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
12
flag_windows.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user