Skip to content

Commit

Permalink
fix: Support limit flag for Box Search (#323)
Browse files Browse the repository at this point in the history
Closes: SDK-2171
Fixes:  #322
  • Loading branch information
lukaszsocha2 authored May 4, 2022
1 parent dc6bd94 commit 0009a77
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/commands/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ class SearchCommand extends BoxCommand {

let results = await this.client.search.query(args.query || null, options);

// Hard limit the search results to avoid slamming the API
// Limit the search results according to the --limit flag value (if specified) or RESULTS_LIMIT value
const itemsLimit = flags.limit || RESULTS_LIMIT;
let limitedResults = [];
for await (let result of { [Symbol.asyncIterator]: () => results }) {
let numResults = limitedResults.push(result);
if (numResults >= RESULTS_LIMIT) {
if (numResults >= itemsLimit) {
break;
}
}
Expand Down Expand Up @@ -284,6 +285,9 @@ SearchCommand.flags = {
'desc'
]
}),
limit: flags.integer({
description: 'Defines the maximum number of items to return. Default value is 100.',
}),
'include-recent-shared-links': flags.boolean({
description: 'Returns shared links that the user recently accessed'
}),
Expand Down

0 comments on commit 0009a77

Please sign in to comment.