diff options
| author | Alex Flint <[email protected]> | 2018-04-15 18:34:32 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-04-15 18:34:32 -0700 |
| commit | b1eda2c7b64c118d56472c1944054bf9235d6c48 (patch) | |
| tree | fbcf34b3dbf7c874ed261ed390c82c6fc933479f /usage.go | |
| parent | 0cc8e30fd64c8c71d094be299ad424da93ef9aed (diff) | |
| parent | 51337ded775c91dc26574d7d2dc2e493cf416138 (diff) | |
Merge pull request #62 from mwlazlo-tls/master
Custom parsers implementing encoding.TextMarshaler() can have default…
Diffstat (limited to 'usage.go')
| -rw-r--r-- | usage.go | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -6,6 +6,7 @@ import ( "os" "reflect" "strings" + "encoding" ) // the width of the left column @@ -134,7 +135,15 @@ func printOption(w io.Writer, spec *spec) { if v.IsValid() { z := reflect.Zero(v.Type()) if (v.Type().Comparable() && z.Type().Comparable() && v.Interface() != z.Interface()) || v.Kind() == reflect.Slice && !v.IsNil() { - fmt.Fprintf(w, " [default: %v]", v) + if scalar, ok := v.Interface().(encoding.TextMarshaler); ok { + if value, err := scalar.MarshalText(); err != nil { + fmt.Fprintf(w, " [default: error: %v]", err) + } else { + fmt.Fprintf(w, " [default: %v]", string(value)) + } + } else { + fmt.Fprintf(w, " [default: %v]", v) + } } } fmt.Fprint(w, "\n") |
