diff --git a/internal/human/marshal.go b/internal/human/marshal.go index 749bdd4ed6..44d87bd177 100644 --- a/internal/human/marshal.go +++ b/internal/human/marshal.go @@ -45,10 +45,12 @@ func Marshal(data interface{}, opt *MarshalOpt) (string, error) { // safely get the marshalerFunc marshalerFunc, _ := getMarshalerFunc(rType) + isNil := isInterfaceNil(data) + isSlice := rType.Kind() == reflect.Slice switch { - // If data is nil - case isInterfaceNil(data): + // If data is nil and is not a slice ( In case of a slice we want to print header row and not a simple dash ) + case isNil && !isSlice: return defaultMarshalerFunc(nil, opt) // If data has a registered MarshalerFunc call it @@ -72,7 +74,7 @@ func Marshal(data interface{}, opt *MarshalOpt) (string, error) { return Marshal(rValue.Elem().Interface(), opt) // If data is a slice uses marshalSlice - case rType.Kind() == reflect.Slice: + case isSlice: return marshalSlice(rValue, opt) // If data is a struct uses marshalStruct diff --git a/internal/namespaces/baremetal/v1/testdata/test-list-server-list-with-tags.golden b/internal/namespaces/baremetal/v1/testdata/test-list-server-list-with-tags.golden index 19ae016325..5d631c1c33 100644 --- a/internal/namespaces/baremetal/v1/testdata/test-list-server-list-with-tags.golden +++ b/internal/namespaces/baremetal/v1/testdata/test-list-server-list-with-tags.golden @@ -1,5 +1,5 @@ 🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 🟩🟩🟩 STDOUT️ 🟩🟩🟩️ -- +ID Name Offer Name Status Tags Ping 🟩🟩🟩 JSON STDOUT 🟩🟩🟩 [] diff --git a/internal/namespaces/baremetal/v1/testdata/test-list-server-simple.golden b/internal/namespaces/baremetal/v1/testdata/test-list-server-simple.golden index 19ae016325..5d631c1c33 100644 --- a/internal/namespaces/baremetal/v1/testdata/test-list-server-simple.golden +++ b/internal/namespaces/baremetal/v1/testdata/test-list-server-simple.golden @@ -1,5 +1,5 @@ 🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 🟩🟩🟩 STDOUT️ 🟩🟩🟩️ -- +ID Name Offer Name Status Tags Ping 🟩🟩🟩 JSON STDOUT 🟩🟩🟩 []