audit cleanup

This commit is contained in:
Dave Eddy 2015-09-08 17:30:08 -04:00
parent c1dcef2f0f
commit f476cc9168
2 changed files with 28 additions and 5 deletions

View File

@ -262,11 +262,22 @@ function humanSizeFromBytes(opts, bytes) {
return format(template, sign, s, sizes[i]); return format(template, sign, s, sizes[i]);
} }
/*
* capitalize the first character of a string and return the new string
*/
function capitalize(s) { function capitalize(s) {
assert.string(s, 's'); assert.string(s, 's');
return s[0].toUpperCase() + s.substr(1); return s[0].toUpperCase() + s.substr(1);
} }
/*
* Convert a UUID to a short ID
*/
function uuidToShortId(s) {
assert.uuid(s, 's');
return s.split('-', 1)[0];
}
/* /*
* Normalize a short ID. Returns undefined if the given string isn't a valid * Normalize a short ID. Returns undefined if the given string isn't a valid
* short id. * short id.
@ -424,6 +435,7 @@ module.exports = {
humanSizeFromBytes: humanSizeFromBytes, humanSizeFromBytes: humanSizeFromBytes,
capitalize: capitalize, capitalize: capitalize,
normShortId: normShortId, normShortId: normShortId,
uuidToShortId: uuidToShortId,
slug: slug, slug: slug,
getCliTableOptions: getCliTableOptions getCliTableOptions: getCliTableOptions
}; };

View File

@ -17,7 +17,10 @@ var common = require('./common');
var errors = require('./errors'); var errors = require('./errors');
// columns default without -o // columns default without -o
var columnsDefault = 'id,time,action,success'; var columnsDefault = 'shortid,time,action,success';
// columns default with -l
var columnsDefaultLong = 'id,time,action,success';
// sort default with -s // sort default with -s
var sortDefault = 'id,time'; var sortDefault = 'id,time';
@ -33,7 +36,14 @@ function do_instance_audit(subcmd, opts, args, cb) {
return cb(new Error('incorrect args: ' + args)); return cb(new Error('incorrect args: ' + args));
} }
var columns = opts.o.split(','); var columns = columnsDefault;
if (opts.o) {
columns = opts.o;
} else if (opts.long) {
columns = columnsDefaultLong;
}
columns = columns.split(',');
var sort = opts.s.split(','); var sort = opts.s.split(',');
var arg = args[0]; var arg = args[0];
@ -62,6 +72,7 @@ function do_instance_audit(subcmd, opts, args, cb) {
audit.forEach(function (a) { audit.forEach(function (a) {
a.id = uuid; a.id = uuid;
a.shortid = common.uuidToShortId(uuid);
}); });
if (opts.json) { if (opts.json) {
@ -79,6 +90,8 @@ function do_instance_audit(subcmd, opts, args, cb) {
} }
} }
do_instance_audit.aliases = ['audit'];
do_instance_audit.options = [ do_instance_audit.options = [
{ {
names: ['help', 'h'], names: ['help', 'h'],
@ -86,7 +99,7 @@ do_instance_audit.options = [
help: 'Show this help.' help: 'Show this help.'
} }
].concat(common.getCliTableOptions({ ].concat(common.getCliTableOptions({
columnsDefault: columnsDefault, includeLong: true,
sortDefault: sortDefault sortDefault: sortDefault
})); }));
@ -99,6 +112,4 @@ do_instance_audit.help = (
+ '{{options}}' + '{{options}}'
); );
module.exports = do_instance_audit; module.exports = do_instance_audit;