diff --git a/ipn/prefs.go b/ipn/prefs.go index fe93c0efd..0d341ae1a 100644 --- a/ipn/prefs.go +++ b/ipn/prefs.go @@ -234,6 +234,20 @@ func (m *MaskedPrefs) Pretty() string { mt := mv.Type() mpv := reflect.ValueOf(&m.Prefs).Elem() first := true + + format := func(v reflect.Value) string { + switch v.Type().Kind() { + case reflect.String: + return "%s=%q" + case reflect.Slice: + // []string + if v.Type().Elem().Kind() == reflect.String { + return "%s=%q" + } + } + return "%s=%v" + } + for i := 1; i < mt.NumField(); i++ { name := mt.Field(i).Name if mv.Field(i).Bool() { @@ -241,9 +255,10 @@ func (m *MaskedPrefs) Pretty() string { sb.WriteString(" ") } first = false - fmt.Fprintf(&sb, "%s=%#v", + f := mpv.Field(i - 1) + fmt.Fprintf(&sb, format(f), strings.TrimSuffix(name, "Set"), - mpv.Field(i-1).Interface()) + f.Interface()) } } sb.WriteString("}") diff --git a/ipn/prefs_test.go b/ipn/prefs_test.go index 1f24fc7a6..41b16b60f 100644 --- a/ipn/prefs_test.go +++ b/ipn/prefs_test.go @@ -615,12 +615,27 @@ func TestMaskedPrefsPretty(t *testing.T) { OperatorUser: "galaxybrain", AllowSingleHosts: true, RouteAll: false, + ExitNodeID: "foo", + AdvertiseTags: []string{"tag:foo", "tag:bar"}, + NetfilterMode: preftype.NetfilterNoDivert, }, - RouteAllSet: true, - HostnameSet: true, - OperatorUserSet: true, + RouteAllSet: true, + HostnameSet: true, + OperatorUserSet: true, + ExitNodeIDSet: true, + AdvertiseTagsSet: true, + NetfilterModeSet: true, }, - want: `MaskedPrefs{RouteAll=false Hostname="bar" OperatorUser="galaxybrain"}`, + want: `MaskedPrefs{RouteAll=false ExitNodeID="foo" AdvertiseTags=["tag:foo" "tag:bar"] Hostname="bar" NetfilterMode=nodivert OperatorUser="galaxybrain"}`, + }, + { + m: &MaskedPrefs{ + Prefs: Prefs{ + ExitNodeIP: netaddr.IPv4(100, 102, 104, 105), + }, + ExitNodeIPSet: true, + }, + want: `MaskedPrefs{ExitNodeIP=100.102.104.105}`, }, } for i, tt := range tests {