list.js
1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var mout = require('mout');
var PackageRepository = require('../../core/PackageRepository');
var defaultConfig = require('../../config');
function list(logger, packages, options, config) {
var repository;
config = defaultConfig(config);
repository = new PackageRepository(config, logger);
// If packages is an empty array, null them
if (packages && !packages.length) {
packages = null;
}
return repository.list()
.then(function (entries) {
if (packages) {
// Filter entries according to the specified packages
entries = entries.filter(function (entry) {
return !!mout.array.find(packages, function (pkg) {
return pkg === entry.pkgMeta.name;
});
});
}
return entries;
});
}
// -------------------
list.readOptions = function (argv) {
var cli = require('../../util/cli');
var options = cli.readOptions(argv);
var packages = options.argv.remain.slice(2);
delete options.argv;
return [packages, options];
};
module.exports = list;