Skip to content
This repository was archived by the owner on Jun 6, 2023. It is now read-only.

Commit 98d3265

Browse files
committed
added summary table for jobs list output
1 parent eef572e commit 98d3265

File tree

3 files changed

+133
-54
lines changed

3 files changed

+133
-54
lines changed

lib/jobs/list.js

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var method = require('./../method');
44
var projectConfig = require('./../projectConfig');
55
var assign = require('lodash.assign');
66
var path = require('path');
7+
var Table = require('table');
78

89
/**
910
* @memberof jobs
@@ -21,6 +22,8 @@ var path = require('path');
2122
* @param {string} [filter.command] - Optional command to match on
2223
* @param {string} [filter.workspace] - Optional workspace path to match on. Note: the original workspace path will be modified on upload to point to a temporary location.
2324
* @param {string} [filter.dataset] - Optional dataset to match on
25+
* @param {string} [filter.dataset] - Optional dataset to match on
26+
* @param {boolean} [summary] - Optional (command line argument only). Format output as a summary table.
2427
* @param {function} cb - Node-style error-first callback function
2528
* @returns {array} [ job, ... ] - JSON array of job objects
2629
* @example
@@ -30,7 +33,7 @@ var path = require('path');
3033
* // handle error or result
3134
* });
3235
* @example
33-
* $ paperspace jobs list --project "MyProject"
36+
* $ paperspace jobs list --project "MyProject" --state Running --summary
3437
* @example
3538
* # HTTP request:
3639
* https://api.paperspace.io
@@ -75,6 +78,11 @@ var path = require('path');
7578
*/
7679

7780
function list(params, cb) {
81+
var summary = false;
82+
if (params.summary) {
83+
summary = params.summary;
84+
delete params.summary;
85+
}
7886
if (!params.project && !params.projectId) {
7987
// default to name of project in .ps_project/config or name of current directory
8088
params.project = projectConfig.getProject();
@@ -91,7 +99,50 @@ function list(params, cb) {
9199
}
92100
}
93101
}
94-
return method(list, params, cb);
102+
return method(list, params, function listCb(err, data) {
103+
if (global.paperspace_cli && summary) {
104+
var tableConfig = {
105+
columns: {
106+
0: {
107+
alignment: 'left'
108+
},
109+
1: {
110+
alignment: 'left'
111+
},
112+
2: {
113+
alignment: 'left'
114+
},
115+
3: {
116+
alignment: 'left'
117+
},
118+
4: {
119+
alignment: 'left'
120+
},
121+
5: {
122+
alignment: 'left'
123+
},
124+
6: {
125+
alignment: 'left',
126+
width: 30
127+
}
128+
}
129+
};
130+
var tableData = [];
131+
132+
if (err) return cb(err);
133+
if (data && data.length) {
134+
tableData.push(['jobId', 'project', 'name', 'state', 'dtCreated', 'exitCode', 'entrypoint']);
135+
data.forEach(function itemFunc(item) {
136+
if (item.id) {
137+
tableData.push([item.id, item.project, item.name, item.state, item.dtCreated, item.exitCode, item.entrypoint]);
138+
}
139+
});
140+
var output = Table.table(tableData, tableConfig);
141+
console.log(output);
142+
}
143+
return cb();
144+
} else return cb(err, data);
145+
});
95146
}
96147

97148
assign(list, {

package-lock.json

Lines changed: 78 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"npm": ">=5.5.1"
2121
},
2222
"dependencies": {
23+
"ajv": "^6.4.0",
2324
"archiver": "^2.1.0",
2425
"async": "1.5.2",
2526
"aws-sdk": "^2.169.0",
@@ -40,6 +41,7 @@
4041
"readline-sync": "^1.4.7",
4142
"route-parser": "0.0.5",
4243
"superagent": "3.8.1",
44+
"table": "^4.0.3",
4345
"yargs": "^5.0.0"
4446
},
4547
"devDependencies": {

0 commit comments

Comments
 (0)