Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ module.exports.parse = function (output) {
// Treat the first line as the title fields line
if (index == 0) {
var fields = line.split(/\s+/);
var currentIndex = 0;

// record the beginning and ending for each field
fields.forEach(function (field, idx) {

if (field) {
var info = titleInfo[field] = {};
var indexBegin = line.indexOf(field);
var indexEnd = indexBegin + field.length;
var indexBegin = line.indexOf(field, currentIndex);
var indexEnd = currentIndex = (indexBegin + field.length);

if (idx == 0) {
info.titleBegin = 0;
Expand Down
4 changes: 4 additions & 0 deletions test/output/ps-repeated-header.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PPID PID COMMAND
1 338 /usr/sbin/distnoted agent
1 341 /usr/libexec/trustd --agent
1 342 /usr/libexec/lsd
31 changes: 31 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,37 @@ describe('tabler-parser', function () {
Assert.deepEqual(result, expectResult);
});

it('with a repeated header', function () {
var output = GetOutput('ps-repeated-header.log');
var result = TableParser.parse(output);

var expectResult = [
{
'PID': ['338'],
'PPID': ['1'],
'COMMAND': [
'/usr/sbin/distnoted',
'agent'
]
},
{
'PID': ['341'],
'PPID': ['1'],
'COMMAND': [
'/usr/libexec/trustd',
'--agent'
]
},
{
'PID': ['342'],
'PPID': ['1'],
'COMMAND': ['/usr/libexec/lsd']
},
];

Assert.deepEqual(result, expectResult);
});

it('a windows output', function () {
var output = GetOutput('wmic.log');
var result = TableParser.parse(output);
Expand Down