From 78a51d2d2ccf0184b52424d06011ae86b444b5f8 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Wed, 18 Feb 2015 13:32:42 -0800 Subject: [PATCH] Shorten printed Windows paths on docker help cmd This makes use of `%USERPROFILE%` as a substitute for `~` on Windows and prints shorter strings for default cert paths etc. Also removes string escaping/quotes around default path values printed in `docker help` command as they are not really necessary and adds double backslashes (\\) on windows. Signed-off-by: Ahmet Alp Balkan --- mflag/flag.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/mflag/flag.go b/mflag/flag.go index cbdd5ea..edb17a2 100644 --- a/mflag/flag.go +++ b/mflag/flag.go @@ -86,12 +86,13 @@ import ( "fmt" "io" "os" - "runtime" "sort" "strconv" "strings" "text/tabwriter" "time" + + "github.com/docker/docker/pkg/homedir" ) // ErrHelp is the error returned if the flag -help is invoked but no such flag is defined. @@ -504,16 +505,9 @@ func Set(name, value string) error { // otherwise, the default values of all defined flags in the set. func (f *FlagSet) PrintDefaults() { writer := tabwriter.NewWriter(f.Out(), 20, 1, 3, ' ', 0) - var home string - if runtime.GOOS != "windows" { - home = os.Getenv("HOME") - } + home := homedir.Get() f.VisitAll(func(flag *Flag) { format := " -%s=%s" - if _, ok := flag.Value.(*stringValue); ok { - // put quotes on the value - format = " -%s=%q" - } names := []string{} for _, name := range flag.Names { if name[0] != '#' { @@ -524,7 +518,7 @@ func (f *FlagSet) PrintDefaults() { val := flag.DefValue if home != "" && strings.HasPrefix(val, home) { - val = "~" + val[len(home):] + val = homedir.GetShortcutString() + val[len(home):] } fmt.Fprintf(writer, format, strings.Join(names, ", -"), val)