Fix for help when $HOME is /

estesp noticed that when $HOME is / the ~ substitutions messes up
becuase it tries to replace all paths that start with "/" with "~".
This fixes it so that it will only replace it when $HOME isn't "/".

Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Doug Davis 2015-02-06 14:17:34 -08:00
parent de0ed79618
commit 9ac0da4578
2 changed files with 21 additions and 5 deletions

View file

@ -86,6 +86,7 @@ import (
"fmt"
"io"
"os"
"runtime"
"sort"
"strconv"
"strings"
@ -505,7 +506,16 @@ 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)
home := homedir.Get()
var home string
if runtime.GOOS != "windows" {
// Only do this on non-windows systems
home = homedir.Get()
// Don't substitute when HOME is /
if home == "/" {
home = ""
}
}
f.VisitAll(func(flag *Flag) {
format := " -%s=%s"
names := []string{}