From 7fff2f8a1c8ac706694ecf29dac4134094cc9090 Mon Sep 17 00:00:00 2001 From: fancl Date: Mon, 29 Apr 2024 15:17:23 +0800 Subject: [PATCH] fix command line exclude column --- entry/cli/serialize.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/entry/cli/serialize.go b/entry/cli/serialize.go index 2b75877..32533bf 100644 --- a/entry/cli/serialize.go +++ b/entry/cli/serialize.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "git.nspix.com/golang/kos/util/arrays" "git.nspix.com/golang/kos/util/pool" "github.com/mattn/go-runewidth" "reflect" @@ -184,6 +185,7 @@ func serializeArray(val []any) (buf []byte, err error) { } if isStructElement { vs = make([][]any, 0, len(val)) + indexes := make([]int, 0) for i, v := range val { rv := reflect.Indirect(reflect.ValueOf(v)) if rv.Kind() == reflect.Struct { @@ -198,13 +200,16 @@ func serializeArray(val []any) (buf []byte, err error) { continue } } + indexes = append(indexes, j) row = append(row, columnName) } vs = append(vs, row) } row := make([]any, 0, rv.Type().NumField()) for j := 0; j < rv.Type().NumField(); j++ { - row = append(row, rv.Field(j).Interface()) + if arrays.Exists(j, indexes) { + row = append(row, rv.Field(j).Interface()) + } } vs = append(vs, row) } else {