close
Skip to content

Commit 57f8d3d

Browse files
author
Matt Willer
authored
Add search sort flags (#131)
1 parent ee387a0 commit 57f8d3d

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎src/commands/search.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ class SearchCommand extends BoxCommand {
130130
options.fields = flags.fields;
131131
}
132132

133+
if (flags.sort) {
134+
options.sort = flags.sort;
135+
}
136+
137+
if (flags.direction) {
138+
options.direction = flags.direction;
139+
}
140+
133141
let results = await this.client.search.query(args.query || null, options);
134142

135143
// Hard limit the search results to avoid slamming the API
@@ -239,6 +247,17 @@ SearchCommand.flags = {
239247
}),
240248
'size-to': flags.integer({
241249
description: 'Upper bound for file size, in bytes',
250+
}),
251+
sort: flags.string({
252+
description: 'The field to sort results by'
253+
}),
254+
direction: flags.string({
255+
description: 'The direction to sort results (ascending or descending)',
256+
dependsOn: ['sort'],
257+
options: [
258+
'asc',
259+
'desc'
260+
]
242261
})
243262
};
244263

‎test/commands/search.test.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ describe('Search', () => {
163163
],
164164
{size_range: '1024,4096'}
165165
],
166+
'sort order flags': [
167+
[
168+
'--sort=modified_at',
169+
'--direction=asc'
170+
],
171+
{
172+
sort: 'modified_at',
173+
direction: 'asc',
174+
}
175+
],
166176
'multitple metadata filters': [
167177
[
168178
'--md-filter-scope=global',

0 commit comments

Comments
 (0)