From f476cc91683637eb8cbd324e0f32224a81b8897d Mon Sep 17 00:00:00 2001 From: Dave Eddy Date: Tue, 8 Sep 2015 17:30:08 -0400 Subject: [PATCH] audit cleanup --- lib/common.js | 12 ++++++++++++ lib/do_instance_audit.js | 21 ++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/common.js b/lib/common.js index 0aaf85a..636c343 100644 --- a/lib/common.js +++ b/lib/common.js @@ -262,11 +262,22 @@ function humanSizeFromBytes(opts, bytes) { return format(template, sign, s, sizes[i]); } +/* + * capitalize the first character of a string and return the new string + */ function capitalize(s) { assert.string(s, 's'); 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 * short id. @@ -424,6 +435,7 @@ module.exports = { humanSizeFromBytes: humanSizeFromBytes, capitalize: capitalize, normShortId: normShortId, + uuidToShortId: uuidToShortId, slug: slug, getCliTableOptions: getCliTableOptions }; diff --git a/lib/do_instance_audit.js b/lib/do_instance_audit.js index bf9c90d..7619e25 100644 --- a/lib/do_instance_audit.js +++ b/lib/do_instance_audit.js @@ -17,7 +17,10 @@ var common = require('./common'); var errors = require('./errors'); // 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 var sortDefault = 'id,time'; @@ -33,7 +36,14 @@ function do_instance_audit(subcmd, opts, args, cb) { 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 arg = args[0]; @@ -62,6 +72,7 @@ function do_instance_audit(subcmd, opts, args, cb) { audit.forEach(function (a) { a.id = uuid; + a.shortid = common.uuidToShortId(uuid); }); if (opts.json) { @@ -79,6 +90,8 @@ function do_instance_audit(subcmd, opts, args, cb) { } } +do_instance_audit.aliases = ['audit']; + do_instance_audit.options = [ { names: ['help', 'h'], @@ -86,7 +99,7 @@ do_instance_audit.options = [ help: 'Show this help.' } ].concat(common.getCliTableOptions({ - columnsDefault: columnsDefault, + includeLong: true, sortDefault: sortDefault })); @@ -99,6 +112,4 @@ do_instance_audit.help = ( + '{{options}}' ); - - module.exports = do_instance_audit;