dryrun output: include name instead of id:nil

When we're creating objects, we tend not to have an id.  Rather than
drop them entirely though, we can print their name (where we have one)
This commit is contained in:
Justin Santa Barbara 2016-12-08 12:53:51 -05:00
parent e2c52a99ce
commit 104332108f
1 changed files with 11 additions and 1 deletions

View File

@ -338,7 +338,17 @@ func ValueAsString(value reflect.Value) string {
} else if compareWithID, ok := intf.(CompareWithID); ok {
id := compareWithID.CompareWithID()
if id == nil {
fmt.Fprintf(b, "id:<nil>")
// Uninformative, but we can often print the name instead
name := ""
hasName, ok := intf.(HasName)
if ok {
name = StringValue(hasName.GetName())
}
if name != "" {
fmt.Fprintf(b, "name:%s", name)
} else {
fmt.Fprintf(b, "id:<nil>")
}
} else {
fmt.Fprintf(b, "id:%s", *id)
}