Skip to content

Commit

Permalink
fix: pretty print when there is no rows (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz authored and knownasilya committed Apr 29, 2019
1 parent 1cf32f0 commit a20ddfc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
16 changes: 6 additions & 10 deletions bin/utils/TablePrinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,22 @@ class TablePrinter {

if (!lines.length) return;

if (!this._hasWritten) {
this.setColumnWidths(lines[0]);
}
if (!this._hasWritten) this.setColumnWidths(lines[0]);

const top = this._hasWritten ? this.middleLine : this.topLine;
this.print(top, lines);
this._hasWritten = true;
}

end(csv) {
const lines = csv.split(this.opts.eol);
this.print(this.middleLine, lines, this.bottomLine);
let lines = csv.split(this.opts.eol);
if (!this._hasWritten) this.setColumnWidths(lines[0]);
const top = this._hasWritten ? this.middleLine : this.topLine;
this.print(top, lines, this.bottomLine);
}

printCSV(csv) {
let lines = csv.split(this.opts.eol);

this.setColumnWidths(lines[0]);

this.print(this.topLine, lines, this.bottomLine);
this.end(csv);
}

setColumnWidths(line) {
Expand Down
12 changes: 11 additions & 1 deletion test/CLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,5 +826,15 @@ module.exports = (testRunner, jsonFixtures, csvFixtures) => {
t.end();
});
});
};

testRunner.add('should print pretty table without rows', (t) => {
const opts = ' --fields fieldA,fieldB,fieldC --pretty';

child_process.exec(cli + '-i ' + getFixturePath('/json/default.json') + opts, (err, stdout, stderr) => {
t.notOk(stderr);
const csv = stdout;
t.equal(csv, csvFixtures.prettyprintWithoutRows);
t.end();
});
});
};
3 changes: 3 additions & 0 deletions test/fixtures/csv/prettyprintWithoutRows.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
┌────────────────┬────────────────┬────────────────┐
│ "fieldA" │ "fieldB" │ "fieldC" │
└────────────────┴────────────────┴────────────────┘

0 comments on commit a20ddfc

Please sign in to comment.