diff --git a/bin/download.js b/bin/download.js index 8b8cd64..40e301d 100644 --- a/bin/download.js +++ b/bin/download.js @@ -24,7 +24,8 @@ exports.builder = { }, l: { alias: 'lang', - description: 'Limit the download to only resources in the given language. e.g. "en"' + description: 'Limit the download to only resources in the given language. e.g. "en"', + array: true }, p: { alias: 'proj', @@ -72,11 +73,8 @@ exports.handler = function(argv) { // if(argv.zip) compression = 'zip'; let client = new Door43Client(argv.index, argv.dir, {compression_method:compression}); let getLanguages = function(lang) { - if(lang) { - return client.index.getSourceLanguage(lang) - .then(function(language) { - return [language]; - }); + if(lang && lang.length > 0) { + return client.index.getSpecificSourceLanguages(lang); } else { return client.index.getSourceLanguages(); } @@ -178,4 +176,4 @@ exports.handler = function(argv) { .catch(function(err) { if(argv.verbose) console.error(err); }); -}; \ No newline at end of file +}; diff --git a/lib/library.js b/lib/library.js index 23dad96..a9e8326 100644 --- a/lib/library.js +++ b/lib/library.js @@ -548,7 +548,21 @@ function Library(sqliteHelper, opts) { } return null; }, - + + /** + * Returns a specific set of source languages + * @param slugs {string[]} an array of language slugs to retrieve + * @returns {string[]} an array of language objects + */ + getSpecificSourceLanguages: function(slugs) { + let questionBuilder = function(items) { + return items.map(function() { + return '?'; + }).join(','); + }; + return query('select * from source_language where slug in (' + questionBuilder(slugs) + ')', slugs); + }, + /** * Returns a list of every source language. * @@ -1132,8 +1146,8 @@ function Library(sqliteHelper, opts) { // TODO: add getTranslation. see android }; - + return this; } -module.exports = Library; \ No newline at end of file +module.exports = Library;