commit
193aa34569
1 changed files with 12 additions and 1 deletions
|
@ -86,6 +86,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -503,6 +504,10 @@ 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
|
||||||
|
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 {
|
if _, ok := flag.Value.(*stringValue); ok {
|
||||||
|
@ -516,7 +521,13 @@ func (f *FlagSet) PrintDefaults() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(names) > 0 {
|
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") {
|
for i, line := range strings.Split(flag.Usage, "\n") {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
line = " " + line
|
line = " " + line
|
||||||
|
|
Loading…
Reference in a new issue