From 022471afa7357886db2237b9c7101df1891472ac Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Mon, 31 Aug 2015 15:16:12 -0700 Subject: [PATCH] triton packages: make --human the default, use -p to override. Nicer, some what kludged sorting by group and memory --- lib/do_packages.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/do_packages.js b/lib/do_packages.js index 42065a7..c312a5e 100644 --- a/lib/do_packages.js +++ b/lib/do_packages.js @@ -46,7 +46,19 @@ function do_packages (subcmd, opts, args, callback) { for (var i = 0; i < pkgs.length; i++) { var pkg = pkgs[i]; pkg.shortid = pkg.id.split('-', 1)[0]; - if (opts.human) { + + /* + * We take a slightly "smarter" view of "group" for default + * sorting, to accomodate usage in the JPC. More recent + * common usage is for packages to have "foo-*" naming. + * JPC includes package sets of yore *and* recent that don't + * use the "group" field. We secondarily separate those + * on a possible "foo-" prefix. + */ + pkg._groupPlus = (pkg.group || (pkg.name.indexOf('-') === -1 + ? "" : pkg.name.split('-', 1)[0])); + + if (!opts.p) { pkg.memoryHuman = common.humanSizeFromBytes({ precision: 1, narrow: true @@ -61,7 +73,7 @@ function do_packages (subcmd, opts, args, callback) { }, pkg.disk * 1024 * 1024); } } - if (opts.human) { + if (!opts.p) { columns = columns.map(function (c) { switch (c) { case 'memory': @@ -113,14 +125,14 @@ do_packages.options = [ { names: ['s'], type: 'string', - default: 'name', - help: 'Sort on the given fields. Default is "name".', + default: '_groupPlus,memory', + help: 'Sort on the given fields. Default is "group,memory".', helpArg: 'field1,...' }, { - names: ['human'], + names: ['p'], type: 'bool', - help: '"Human-readable" output. Show MiB, GiB, etc units for sizes.' + help: 'Display numbers in parsable (exact) values.' }, { names: ['json', 'j'],