summaryrefslogtreecommitdiff
path: root/usage.go
diff options
context:
space:
mode:
Diffstat (limited to 'usage.go')
-rw-r--r--usage.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/usage.go b/usage.go
index 4652b36..656ee9a 100644
--- a/usage.go
+++ b/usage.go
@@ -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")