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

use csv-string package to format --csv output #69

Merged
merged 11 commits into from
Nov 1, 2018
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@justinbeckwith/sloth",
"version": "1.9.0",
"version": "2.0.1",
"repository": "justinbeckwith/sloth",
"description": "sloth is a CLI utility for measuring GitHub response SLOs.",
"bin": {
Expand Down Expand Up @@ -32,8 +32,9 @@
"author": "Justin Beckwith",
"license": "Apache-2.0",
"dependencies": {
"@octokit/rest": "^15.8.1",
"@octokit/rest": "^15.15.1",
"cli-table": "^0.3.1",
"csv-string": "^3.1.5",
"meow": "^5.0.0",
"truncate": "^2.0.1",
"update-notifier": "^2.5.0"
Expand All @@ -42,10 +43,10 @@
"@types/cli-table": "^0.3.0",
"@types/meow": "^5.0.0",
"@types/mocha": "^5.2.1",
"@types/node": "^10.3.0",
"@types/update-notifier": "^2.2.0",
"@types/node": "^10.12.1",
"@types/update-notifier": "^2.5.0",
"gts": "^0.8.0",
"mocha": "^5.2.0",
"typescript": "~3.1.0"
"typescript": "^3.1.4"
}
}
9 changes: 6 additions & 3 deletions src/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {octo, repos} from './util';
import Table = require('cli-table');
import {isTriaged, isOutOfSLO, hasLabel, isApi, isPullRequest, hoursOld, getApi} from './slo';
const truncate = require('truncate');
const CSV = require('csv-string');

export async function getIssues(): Promise<IssueResult[]> {
const promises = new Array<Promise<IssueResult>>();
Expand Down Expand Up @@ -171,8 +172,9 @@ export async function showIssues(flags: Flags) {
let table: Table;
const output = new Array<string>();
const head = ['Issue', 'Triaged', 'InSLO', 'Title', 'Language', 'API', 'Pri'];

if (options.csv) {
output.push(head.join(','));
output.push(CSV.stringify(head));
} else {
table = new Table({head});
}
Expand All @@ -186,7 +188,7 @@ export async function showIssues(flags: Flags) {
issue.pri || ''
];
if (options.csv) {
output.push(values.join(','));
output.push(CSV.stringify(values));
} else {
table.push(values);
}
Expand All @@ -196,5 +198,6 @@ export async function showIssues(flags: Flags) {
output.push(table!.toString());
}

output.forEach(l => console.log(l));
output.forEach(l => process.stdout.write(l));
process.stdout.write('\n');
}