From 9bc2b3482b960ed00d27f72c36e60ff90fe4f0c2 Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Tue, 3 Feb 2015 19:51:35 -0800 Subject: [PATCH] Pretty the help text This modifies the "docker help" text so that it is no wider than 80 chars and each description fits on one line. This will also try to use ~ when possible Added a test to make sure we don't go over 80 chars again. Added a test to make sure we use ~ Applied rules/tests to all docker commands - not just main help text Closes #10214 Signed-off-by: Doug Davis --- mflag/flag.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mflag/flag.go b/mflag/flag.go index 94cb5b7..cbdd5ea 100644 --- a/mflag/flag.go +++ b/mflag/flag.go @@ -86,6 +86,7 @@ import ( "fmt" "io" "os" + "runtime" "sort" "strconv" "strings" @@ -503,6 +504,10 @@ 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") + } f.VisitAll(func(flag *Flag) { format := " -%s=%s" if _, ok := flag.Value.(*stringValue); ok { @@ -516,7 +521,13 @@ func (f *FlagSet) PrintDefaults() { } } if len(names) > 0 { - fmt.Fprintf(writer, format, strings.Join(names, ", -"), flag.DefValue) + val := flag.DefValue + + if home != "" && strings.HasPrefix(val, home) { + val = "~" + val[len(home):] + } + + fmt.Fprintf(writer, format, strings.Join(names, ", -"), val) for i, line := range strings.Split(flag.Usage, "\n") { if i != 0 { line = " " + line