Browse Source

fix command line exclude column

fancl 10 months ago
parent
commit
7fff2f8a1c
1 changed files with 6 additions and 1 deletions
  1. 6 1
      entry/cli/serialize.go

+ 6 - 1
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 {