feat: allowing count to be passed to ./nodebb events

This commit is contained in:
Julian Lam
2019-06-12 13:19:28 -04:00
parent de04629745
commit f6d3cc0ea4
3 changed files with 14 additions and 9 deletions

View File

@@ -210,10 +210,10 @@ program
}) })
.description('List all installed plugins'); .description('List all installed plugins');
program program
.command('events') .command('events [count]')
.description('Outputs the last ten (10) administrative events recorded by NodeBB') .description('Outputs the most recent administrative events recorded by NodeBB')
.action(function () { .action(function (count) {
require('./manage').listEvents(); require('./manage').listEvents(count);
}); });
program program
.command('info') .command('info')

View File

@@ -97,10 +97,10 @@ function listPlugins() {
}); });
} }
function listEvents() { function listEvents(count) {
async.series([ async.series([
db.init, db.init,
events.output, async.apply(events.output, count),
]); ]);
} }

View File

@@ -193,9 +193,14 @@ events.deleteAll = function (callback) {
}, { alwaysStartAt: 0 }, callback); }, { alwaysStartAt: 0 }, callback);
}; };
events.output = function () { events.output = function (numEvents) {
console.log('\nDisplaying last ten administrative events...'.bold); numEvents = parseInt(numEvents, 10);
events.getEvents('', 0, 9, function (err, events) { if (isNaN(numEvents)) {
numEvents = 10;
}
console.log(('\nDisplaying last ' + numEvents + ' administrative events...').bold);
events.getEvents('', 0, numEvents - 1, function (err, events) {
if (err) { if (err) {
winston.error('Error fetching events', err); winston.error('Error fetching events', err);
throw err; throw err;