Skip to content

Commit

Permalink
updated cli to support downloading multiple specific languages
Browse files Browse the repository at this point in the history
  • Loading branch information
da1nerd committed Jun 19, 2019
1 parent 18f5183 commit b1e8240
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
12 changes: 5 additions & 7 deletions bin/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -178,4 +176,4 @@ exports.handler = function(argv) {
.catch(function(err) {
if(argv.verbose) console.error(err);
});
};
};
20 changes: 17 additions & 3 deletions lib/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -1132,8 +1146,8 @@ function Library(sqliteHelper, opts) {

// TODO: add getTranslation. see android
};

return this;
}

module.exports = Library;
module.exports = Library;

0 comments on commit b1e8240

Please sign in to comment.