@@ -59,18 +59,20 @@ class Table<T extends object> {
5959 } )
6060
6161 // filter rows
62- if ( this . options . filter ) {
63- /* eslint-disable-next-line prefer-const */
64- let [ header , regex ] = this . options . filter ! . split ( '=' )
65- const isNot = header [ 0 ] === '-'
66- if ( isNot ) header = header . substr ( 1 )
67- const col = this . findColumnFromHeader ( header )
68- if ( ! col || ! regex ) throw new Error ( 'Filter flag has an invalid value' )
69- rows = rows . filter ( ( d : any ) => {
70- const re = new RegExp ( regex )
71- const val = d [ col ! . key ]
72- const match = val . match ( re )
73- return isNot ? ! match : match
62+ if ( ! _ . isEmpty ( this . options . filter ) ) {
63+ this . options . filter ! . forEach ( filter => {
64+ /* eslint-disable-next-line prefer-const */
65+ let [ header , regex ] = filter . split ( '=' )
66+ const isNot = header [ 0 ] === '-'
67+ if ( isNot ) header = header . substr ( 1 )
68+ const col = this . findColumnFromHeader ( header )
69+ if ( ! col || ! regex ) throw new Error ( 'Filter flag has an invalid value' )
70+ rows = rows . filter ( ( d : any ) => {
71+ const re = new RegExp ( regex )
72+ const val = d [ col ! . key ]
73+ const match = re . test ( val )
74+ return isNot ? ! match : match
75+ } )
7476 } )
7577 }
7678
@@ -289,7 +291,7 @@ export namespace table {
289291 export const Flags : {
290292 columns : F . IOptionFlag < string | undefined > ;
291293 sort : F . IOptionFlag < string | undefined > ;
292- filter : F . IOptionFlag < string | undefined > ;
294+ filter : F . IOptionFlag < string [ ] | undefined > ;
293295 csv : F . IFlag < boolean > ;
294296 output : F . IOptionFlag < string | undefined > ;
295297 extended : F . IFlag < boolean > ;
@@ -298,7 +300,7 @@ export namespace table {
298300 } = {
299301 columns : F . string ( { exclusive : [ 'extended' ] , description : 'only show provided columns (comma-separated)' } ) ,
300302 sort : F . string ( { description : 'property to sort by (prepend \'-\' for descending)' } ) ,
301- filter : F . string ( { description : 'filter property by partial string matching, ex: name=foo' } ) ,
303+ filter : F . string ( { description : 'filter property by partial string matching, ex: name=foo' , multiple : true } ) ,
302304 csv : F . boolean ( { exclusive : [ 'no-truncate' ] , description : 'output is csv format [alias: --output=csv]' } ) ,
303305 output : F . string ( {
304306 exclusive : [ 'no-truncate' , 'csv' ] ,
@@ -346,7 +348,7 @@ export namespace table {
346348 export interface Options {
347349 [ key : string ] : any ;
348350 sort ?: string ;
349- filter ?: string ;
351+ filter ?: string [ ] ;
350352 columns ?: string ;
351353 extended ?: boolean ;
352354 'no-truncate' ?: boolean ;
0 commit comments