@@ -8,26 +8,48 @@ class MetadataQueryCommand extends BoxCommand {
88 async run ( ) {
99 const { flags, args } = await this . parse ( MetadataQueryCommand ) ;
1010
11- const { extra_fields : extraFields , ...rest } = mapKeys (
12- omit ( flags , Object . keys ( BoxCommand . flags ) ) ,
13- ( value , key ) => snakeCase ( key )
11+ const {
12+ extra_fields : extraFields ,
13+ query_params : queryParams ,
14+ query_param : queryParam ,
15+ query_param_array : queryParamArray ,
16+ ...rest
17+ } = mapKeys ( omit ( flags , Object . keys ( BoxCommand . flags ) ) , ( value , key ) =>
18+ snakeCase ( key ) ,
1419 ) ;
1520
21+ let combinedQueryParams = queryParams || { } ;
22+ if ( queryParam ) {
23+ combinedQueryParams = {
24+ ...combinedQueryParams ,
25+ ...queryParam ,
26+ } ;
27+ }
28+ if ( queryParamArray ) {
29+ combinedQueryParams = {
30+ ...combinedQueryParams ,
31+ ...queryParamArray ,
32+ } ;
33+ }
34+
1635 const items = await this . client . metadata . query (
1736 args . from ,
1837 args . ancestorFolderId ,
1938 {
2039 ...( extraFields && { fields : extraFields } ) ,
40+ ...( combinedQueryParams && { query_params : combinedQueryParams } ) ,
2141 ...rest ,
22- }
42+ } ,
2343 ) ;
2444 await this . output ( items ) ;
2545 }
2646}
2747
2848MetadataQueryCommand . description =
2949 'Create a search using SQL-like syntax to return items that match specific metadata' ;
30- MetadataQueryCommand . examples = [ 'box metadata-query enterprise_12345.someTemplate 5555 --query "amount >= :minAmount AND amount <= :maxAmount" --query-params minAmount=100f,maxAmount=200f --use-index amountAsc --order-by amount=ASC --extra-fields created_at,metadata.enterprise_1234.contracts' ] ;
50+ MetadataQueryCommand . examples = [
51+ 'box metadata-query enterprise_12345.someTemplate 5555 --query "amount >= :minAmount AND amount <= :maxAmount" --query-params minAmount=100f,maxAmount=200f --use-index amountAsc --order-by amount=ASC --extra-fields created_at,metadata.enterprise_1234.contracts' ,
52+ ] ;
3153MetadataQueryCommand . _endpoint = 'post_metadata_queries_execute_read' ;
3254
3355MetadataQueryCommand . flags = {
@@ -36,16 +58,14 @@ MetadataQueryCommand.flags = {
3658 description : 'The logical expression of the query' ,
3759 } ) ,
3860 'query-params' : Flags . string ( {
39- description : 'Required if query present. The arguments for the query.' ,
61+ description :
62+ 'The arguments for the query. Can be specified as a comma-separated list of key-value pairs. i.e. key1=value1,key2=value2' ,
4063 dependsOn : [ 'query' ] ,
4164 parse ( input ) {
4265 return Object . assign (
4366 { } ,
44- ...input . split ( ',' ) . map ( param => {
45- const [
46- key ,
47- value
48- ] = param . split ( '=' ) ;
67+ ...input . split ( ',' ) . map ( ( param ) => {
68+ const [ key , value ] = param . split ( '=' ) ;
4969 /* eslint-disable multiline-ternary */
5070 return {
5171 [ key ] :
@@ -54,22 +74,42 @@ MetadataQueryCommand.flags = {
5474 : value ,
5575 } ;
5676 /* eslint-enable multiline-ternary */
57- } )
77+ } ) ,
5878 ) ;
5979 } ,
6080 } ) ,
81+ 'query-param' : Flags . string ( {
82+ description : 'One query param key-value pair, i.e. key=value. If this key duplicates with query-params, this flag will take precedence.' ,
83+ dependsOn : [ 'query' ] ,
84+ parse ( input ) {
85+ const key = input . split ( '=' ) [ 0 ] ;
86+ const value = input . substring ( key . length + 1 ) ;
87+ return {
88+ [ key ] : value ,
89+ } ;
90+ } ,
91+ } ) ,
92+ 'query-param-array' : Flags . string ( {
93+ description :
94+ 'One query param key-multiple-value pair, use for multiple-values fields, i.e. key=value1,value2,value3. If this key duplicates with query-params or query-param, this flag will take precedence.' ,
95+ dependsOn : [ 'query' ] ,
96+ parse ( input ) {
97+ const key = input . split ( '=' ) [ 0 ] ;
98+ const value = input . substring ( key . length + 1 ) . split ( ',' ) ;
99+ return {
100+ [ key ] : value ,
101+ } ;
102+ } ,
103+ } ) ,
61104 'use-index' : Flags . string ( {
62105 description : 'The name of the search index to use for this query.' ,
63106 } ) ,
64107 'order-by' : Flags . string ( {
65108 description :
66109 'A list of template fields and directions to sort the metadata query results by.' ,
67110 parse ( input ) {
68- return input . split ( ',' ) . map ( param => {
69- const [
70- fieldKey ,
71- direction
72- ] = param . split ( '=' ) ;
111+ return input . split ( ',' ) . map ( ( param ) => {
112+ const [ fieldKey , direction ] = param . split ( '=' ) ;
73113 return { field_key : fieldKey , direction } ;
74114 } ) ;
75115 } ,
0 commit comments