triton packages: make --human the default, use -p to override. Nicer, some what kludged sorting by group and memory

This commit is contained in:
Trent Mick 2015-08-31 15:16:12 -07:00
parent 016e2d94f0
commit 022471afa7
1 changed files with 18 additions and 6 deletions

View File

@ -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'],