@@ -28,15 +28,23 @@ exports.builder = {
28
28
describe : 'Truncate results to given count' ,
29
29
type : 'number'
30
30
} ,
31
- 'filter.<field>' : {
31
+ 'filter' : {
32
+ group : 'Filtering' ,
32
33
describe : 'Filter results by one or more field values' ,
34
+ type : 'array'
35
+ } ,
36
+ 'filter.<field>[=<value>]' : {
37
+ group : 'Filtering' ,
38
+ describe : 'Field to filter by'
33
39
} ,
34
40
fields : {
41
+ group : 'Field selection' ,
35
42
describe : 'List of fields to order/limit output columns with' ,
36
43
type : 'array'
37
44
} ,
38
- 'fields.<from>' : {
39
- describe : 'Fields to remap' ,
45
+ 'fields.<from>=<to>' : {
46
+ group : 'Field selection' ,
47
+ describe : 'Field to remap' ,
40
48
type : 'array'
41
49
}
42
50
} ;
@@ -125,11 +133,25 @@ async function* limitResult(result, limit) {
125
133
}
126
134
127
135
async function * mapResult ( result , fields ) {
136
+ if ( ! Array . isArray ( fields ) ) {
137
+ const fieldsObject = fields ;
138
+ fields = [ ] ;
139
+ for ( const fromKey in fieldsObject ) {
140
+ const fieldMap = { } ;
141
+ fieldMap [ fromKey ] = fieldsObject [ fromKey ] ;
142
+ fields . push ( fieldMap ) ;
143
+ }
144
+ }
145
+
128
146
for await ( const record of result ) {
129
147
const output = { } ;
130
148
131
149
for ( const field of fields ) {
132
- if ( typeof field == 'object' ) {
150
+ if ( Array . isArray ( field ) ) {
151
+ for ( const fieldValue of field ) {
152
+ output [ fieldValue ] = record [ fieldValue ] ;
153
+ }
154
+ } else if ( typeof field == 'object' ) {
133
155
for ( const from in field ) {
134
156
output [ field [ from ] ] = record [ from ] ;
135
157
}
0 commit comments