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

Commit

Permalink
added summary table for jobs list output
Browse files Browse the repository at this point in the history
  • Loading branch information
sanfilip committed Apr 25, 2018
1 parent eef572e commit 98d3265
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 54 deletions.
55 changes: 53 additions & 2 deletions lib/jobs/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var method = require('./../method');
var projectConfig = require('./../projectConfig');
var assign = require('lodash.assign');
var path = require('path');
var Table = require('table');

/**
* @memberof jobs
Expand All @@ -21,6 +22,8 @@ var path = require('path');
* @param {string} [filter.command] - Optional command to match on
* @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.
* @param {string} [filter.dataset] - Optional dataset to match on
* @param {string} [filter.dataset] - Optional dataset to match on
* @param {boolean} [summary] - Optional (command line argument only). Format output as a summary table.
* @param {function} cb - Node-style error-first callback function
* @returns {array} [ job, ... ] - JSON array of job objects
* @example
Expand All @@ -30,7 +33,7 @@ var path = require('path');
* // handle error or result
* });
* @example
* $ paperspace jobs list --project "MyProject"
* $ paperspace jobs list --project "MyProject" --state Running --summary
* @example
* # HTTP request:
* https://api.paperspace.io
Expand Down Expand Up @@ -75,6 +78,11 @@ var path = require('path');
*/

function list(params, cb) {
var summary = false;
if (params.summary) {
summary = params.summary;
delete params.summary;
}
if (!params.project && !params.projectId) {
// default to name of project in .ps_project/config or name of current directory
params.project = projectConfig.getProject();
Expand All @@ -91,7 +99,50 @@ function list(params, cb) {
}
}
}
return method(list, params, cb);
return method(list, params, function listCb(err, data) {
if (global.paperspace_cli && summary) {
var tableConfig = {
columns: {
0: {
alignment: 'left'
},
1: {
alignment: 'left'
},
2: {
alignment: 'left'
},
3: {
alignment: 'left'
},
4: {
alignment: 'left'
},
5: {
alignment: 'left'
},
6: {
alignment: 'left',
width: 30
}
}
};
var tableData = [];

if (err) return cb(err);
if (data && data.length) {
tableData.push(['jobId', 'project', 'name', 'state', 'dtCreated', 'exitCode', 'entrypoint']);
data.forEach(function itemFunc(item) {
if (item.id) {
tableData.push([item.id, item.project, item.name, item.state, item.dtCreated, item.exitCode, item.entrypoint]);
}
});
var output = Table.table(tableData, tableConfig);
console.log(output);
}
return cb();
} else return cb(err, data);
});
}

assign(list, {
Expand Down
130 changes: 78 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"npm": ">=5.5.1"
},
"dependencies": {
"ajv": "^6.4.0",
"archiver": "^2.1.0",
"async": "1.5.2",
"aws-sdk": "^2.169.0",
Expand All @@ -40,6 +41,7 @@
"readline-sync": "^1.4.7",
"route-parser": "0.0.5",
"superagent": "3.8.1",
"table": "^4.0.3",
"yargs": "^5.0.0"
},
"devDependencies": {
Expand Down

0 comments on commit 98d3265

Please sign in to comment.