Skip to content
This repository was archived by the owner on May 29, 2020. It is now read-only.

Commit 514b9dc

Browse files
committed
collections list & print table
1 parent 7522baf commit 514b9dc

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

itemsapi-collections.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,38 @@
33
var program = require('commander');
44
var service = require('./src/collections')
55
var colors = require('colors');
6+
var Table = require('cli-table');
7+
var _ = require('lodash')
68

79
program
8-
.usage('test')
910
.option('-a, --api [api]', 'ItemsAPI URL i.e. http://localhost:4000/api/v1')
11+
//.usage('test')
1012

1113
program
1214
.command('list')
1315
.description('List all collections')
14-
.option('-a, --api [api]', 'ItemsAPI URL i.e. http://localhost:4000/api/v1')
1516
.action(function(options){
1617
if (!program.api) {
1718
console.log(`The --api parameter is required`.red)
19+
process.exit()
1820
}
19-
//console.log(program.api);
2021

2122
options.api = program.api
2223

2324
service.list(options)
24-
.then(function(val) {
25-
console.log(val)
25+
.then(function(res) {
26+
27+
var table = new Table({
28+
head: ['Name', 'Url']
29+
})
30+
31+
var rows = _.map(res, function(val) {
32+
table.push([val.name, program.api + '/items/' + val.name])
33+
//return [val.name, 'fff']
34+
})
35+
36+
console.log(table.toString());
37+
2638
})
2739
.catch(function(err) {
2840
console.log(err)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "itemsapi-cli",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "The command line interface for ItemsAPI",
55
"main": "index.js",
66
"scripts": {
@@ -28,6 +28,7 @@
2828
"dependencies": {
2929
"JSONStream": "^1.2.1",
3030
"bluebird": "^3.4.6",
31+
"cli-table": "^0.3.1",
3132
"colors": "^1.1.2",
3233
"commander": "^2.9.0",
3334
"itemsapi-node": "^1.0.17",

src/collections.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ var _ = require('lodash');
33
var Promise = require('bluebird');
44

55
exports.list = function(data) {
6-
return new Promise(function(resolve, reject) {
7-
return resolve('Collections list')
6+
var client = new ItemsAPI(data.api)
7+
8+
return client.getCollections()
9+
.then(function(res) {
10+
return res.data.items
811
})
12+
/*return new Promise(function(resolve, reject) {
13+
return resolve('Collections list')
14+
})*/
915
}

0 commit comments

Comments
 (0)