43 availableOptions: [ |
43 availableOptions: [ |
44 { name: 'type', type: String, default: 'documents', aliases: ['t'], description: 'type of obejcts to downloads' }, |
44 { name: 'type', type: String, default: 'documents', aliases: ['t'], description: 'type of obejcts to downloads' }, |
45 { name: 'url', type: String, aliases: ['u'], description: 'Source url' }, |
45 { name: 'url', type: String, aliases: ['u'], description: 'Source url' }, |
46 { name: 'dest', type: String, aliases: ['d'], description: 'File destination' }, |
46 { name: 'dest', type: String, aliases: ['d'], description: 'File destination' }, |
47 { name: 'page', type: Number, default: 1 , aliases: ['p'], description: 'number of page to download'}, |
47 { name: 'page', type: Number, default: 1 , aliases: ['p'], description: 'number of page to download'}, |
48 { name: 'format', type: String, default: 'es6' , aliases: ['f'], description: 'Format for module export, es6 or require'} |
48 { name: 'format', type: String, default: 'es6' , aliases: ['f'], description: 'Format for module export, es6 or require'}, |
|
49 { name: 'extra', type: String, default: '', aliases: ['e'], description: 'additionnal data to download (comma separated list of document ids)'} |
49 ], |
50 ], |
50 dl_countmap: function(commandOptions, rootKey) { |
51 dl_countmap: function(commandOptions, rootKey) { |
51 var done = Q.defer(); |
52 var done = Q.defer(); |
52 var that = this; |
53 var that = this; |
53 request.get({url: commandOptions.url, json: true}, function (err, res, body) { |
54 request.get({url: commandOptions.url, json: true}, function (err, res, body) { |
77 return this.dl_countmap(commandOptions, 'themes'); |
78 return this.dl_countmap(commandOptions, 'themes'); |
78 }, |
79 }, |
79 dl_documents_ids: function(commandOptions, rawArgs, ids) { |
80 dl_documents_ids: function(commandOptions, rawArgs, ids) { |
80 var nextPageUrl = commandOptions.url; |
81 var nextPageUrl = commandOptions.url; |
81 var pageIndex = 1; |
82 var pageIndex = 1; |
|
83 |
|
84 ids.push.apply(ids,commandOptions.extra.split(',')); |
82 |
85 |
83 return promiseWhile( |
86 return promiseWhile( |
84 function() { return pageIndex <= commandOptions.page && nextPageUrl; }, |
87 function() { return pageIndex <= commandOptions.page && nextPageUrl; }, |
85 function() { |
88 function() { |
86 var deferred = Q.defer(); |
89 var deferred = Q.defer(); |
147 dl_documents: function(commandOptions, rawArgs) { // eslint-disable-line no-unused-vars |
150 dl_documents: function(commandOptions, rawArgs) { // eslint-disable-line no-unused-vars |
148 |
151 |
149 var ids = []; |
152 var ids = []; |
150 |
153 |
151 return this.dl_documents_ids(commandOptions, rawArgs, ids).then(function() { |
154 return this.dl_documents_ids(commandOptions, rawArgs, ids).then(function() { |
|
155 console.log(ids); |
152 return Q.all(_.map(ids, function(id) { |
156 return Q.all(_.map(ids, function(id) { |
153 var deferred = Q.defer(); |
157 var deferred = Q.defer(); |
154 request.get({url: commandOptions.url + encodeURIComponent(encodeURIComponent(id)), json: true}, function (err, res, body) { |
158 request.get({url: commandOptions.url + encodeURIComponent(encodeURIComponent(id)), json: true}, function (err, res, body) { |
155 if (err) { |
159 if (err) { |
156 return deferred.reject(err); |
160 return deferred.reject(err); |