-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathamb-search
executable file
·51 lines (42 loc) · 1.19 KB
/
amb-search
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
44
45
46
47
48
49
50
51
#!/usr/bin/env node
require('colorful').colorful();
var commander = require('commander');
var log = require('spm-log');
var print = require('../lib/utils/print');
var search = require('../lib/client').search;
commander
.usage('[options] <query>')
.option('--registry <url>', 'registry url of yuan server')
.option('--verbose', 'show more log')
.option('--no-color', 'disable colorful print');
commander.on('--help', function() {
console.log();
console.log(' ' + 'Examples:'.to.bold.blue);
console.log();
console.log(' $', 'spm search'.to.magenta.color, 'dom');
console.log();
});
commander.parse(process.argv);
if (!commander.args[0]) {
process.stdout.write(commander.helpInformation());
commander.emit('--help');
process.exit();
}
console.log();
log.config(commander);
search({
name: commander.args[0],
registry: commander.registry || require('../lib/config.json').registry,
}, function(err, body) {
if (err) {
log.error('exit', err.message);
process.exit(2);
}
console.log(' ', (body.data.total + ' results').to.bold.color);
console.log('');
var arr = body.data.results;
arr.forEach(function(pkg) {
print(pkg, commander);
console.log('');
});
});