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 <ahmetalpbalkan@gmail.com>
This commit is contained in:
parent
3907f3c2b6
commit
78a51d2d2c
1 changed files with 4 additions and 10 deletions
|
@ -86,12 +86,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/homedir"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrHelp is the error returned if the flag -help is invoked but no such flag is defined.
|
// 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.
|
// otherwise, the default values of all defined flags in the set.
|
||||||
func (f *FlagSet) PrintDefaults() {
|
func (f *FlagSet) PrintDefaults() {
|
||||||
writer := tabwriter.NewWriter(f.Out(), 20, 1, 3, ' ', 0)
|
writer := tabwriter.NewWriter(f.Out(), 20, 1, 3, ' ', 0)
|
||||||
var home string
|
home := homedir.Get()
|
||||||
if runtime.GOOS != "windows" {
|
|
||||||
home = os.Getenv("HOME")
|
|
||||||
}
|
|
||||||
f.VisitAll(func(flag *Flag) {
|
f.VisitAll(func(flag *Flag) {
|
||||||
format := " -%s=%s"
|
format := " -%s=%s"
|
||||||
if _, ok := flag.Value.(*stringValue); ok {
|
|
||||||
// put quotes on the value
|
|
||||||
format = " -%s=%q"
|
|
||||||
}
|
|
||||||
names := []string{}
|
names := []string{}
|
||||||
for _, name := range flag.Names {
|
for _, name := range flag.Names {
|
||||||
if name[0] != '#' {
|
if name[0] != '#' {
|
||||||
|
@ -524,7 +518,7 @@ func (f *FlagSet) PrintDefaults() {
|
||||||
val := flag.DefValue
|
val := flag.DefValue
|
||||||
|
|
||||||
if home != "" && strings.HasPrefix(val, home) {
|
if home != "" && strings.HasPrefix(val, home) {
|
||||||
val = "~" + val[len(home):]
|
val = homedir.GetShortcutString() + val[len(home):]
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(writer, format, strings.Join(names, ", -"), val)
|
fmt.Fprintf(writer, format, strings.Join(names, ", -"), val)
|
||||||
|
|
Loading…
Reference in a new issue