shortid by default for 'triton images', works for 'triton image SHORTID', 'triton create ...'
This commit is contained in:
parent
d0ee7f4153
commit
1d0fa26633
12
TODO.txt
12
TODO.txt
@ -1,8 +1,11 @@
|
|||||||
bash completion (subcmd options)
|
|
||||||
bash completion (cached data: insts, imgs, pkgs, names and ids)
|
|
||||||
|
|
||||||
"shortid" instead of full UUID "id" in default output, and then allow lookup
|
"shortid" instead of full UUID "id" in default output, and then allow lookup
|
||||||
by that shortid. Really nice for 80 columns.
|
by that shortid. Really nice for 80 columns.
|
||||||
|
- images
|
||||||
|
- packages
|
||||||
|
- insts
|
||||||
|
- networks
|
||||||
|
|
||||||
|
triton create -n|--dry-run # does the fake delay, shows what img/pkg/etc.
|
||||||
|
|
||||||
image "name@version" in 'triton insts' table. Optionally?
|
image "name@version" in 'triton insts' table. Optionally?
|
||||||
|
|
||||||
@ -38,6 +41,9 @@ triton info
|
|||||||
|
|
||||||
# maybe today
|
# maybe today
|
||||||
|
|
||||||
|
bash completion (subcmd options)
|
||||||
|
bash completion (cached data: insts, imgs, pkgs, names and ids)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
triton images
|
triton images
|
||||||
|
@ -17,8 +17,13 @@ function do_images(subcmd, opts, args, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var columns = 'shortid,name,version,state,flags,os,pubdate'.split(',');
|
||||||
|
if (opts.o) {
|
||||||
/* JSSTYLED */
|
/* JSSTYLED */
|
||||||
var columns = opts.o.trim().split(/\s*,\s*/g);
|
columns = opts.o.trim().split(/\s*,\s*/g);
|
||||||
|
} else if (opts.long) {
|
||||||
|
columns[0] = 'id';
|
||||||
|
}
|
||||||
/* JSSTYLED */
|
/* JSSTYLED */
|
||||||
var sort = opts.s.trim().split(/\s*,\s*/g);
|
var sort = opts.s.trim().split(/\s*,\s*/g);
|
||||||
|
|
||||||
@ -104,10 +109,14 @@ do_images.options = [
|
|||||||
{
|
{
|
||||||
names: ['o'],
|
names: ['o'],
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: 'id,name,version,state,flags,os,pubdate',
|
|
||||||
help: 'Specify fields (columns) to output.',
|
help: 'Specify fields (columns) to output.',
|
||||||
helpArg: 'field1,...'
|
helpArg: 'field1,...'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
names: ['long', 'l'],
|
||||||
|
type: 'bool',
|
||||||
|
help: 'Long/wider output. Ignored if "-o ..." is used.'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
names: ['s'],
|
names: ['s'],
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
@ -106,8 +106,10 @@ Triton.prototype._cloudapiFromProfile = function _cloudapiFromProfile(profile) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an image by ID or name. If there is more than one image with that name,
|
* Get an image by ID, exact name, or short ID, in that order.
|
||||||
* then the latest (by published_at) is returned.
|
*
|
||||||
|
* If there is more than one image with that name, then the latest
|
||||||
|
* (by published_at) is returned.
|
||||||
*/
|
*/
|
||||||
Triton.prototype.getImage = function getImage(name, cb) {
|
Triton.prototype.getImage = function getImage(name, cb) {
|
||||||
assert.string(name, 'name');
|
assert.string(name, 'name');
|
||||||
@ -129,19 +131,29 @@ Triton.prototype.getImage = function getImage(name, cb) {
|
|||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
var nameMatches = [];
|
var nameMatches = [];
|
||||||
|
var shortIdMatches = [];
|
||||||
for (var i = 0; i < imgs.length; i++) {
|
for (var i = 0; i < imgs.length; i++) {
|
||||||
if (imgs[i].name === name) {
|
var img = imgs[i];
|
||||||
nameMatches.push(imgs[i]);
|
if (img.name === name) {
|
||||||
|
nameMatches.push(img);
|
||||||
|
}
|
||||||
|
if (img.id.slice(0, 8) === name) {
|
||||||
|
shortIdMatches.push(img);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nameMatches.length === 0) {
|
if (nameMatches.length === 1) {
|
||||||
cb(new Error(format('no image with name=%s was found',
|
|
||||||
name)));
|
|
||||||
} else if (nameMatches.length === 1) {
|
|
||||||
cb(null, nameMatches[0]);
|
cb(null, nameMatches[0]);
|
||||||
} else {
|
} else if (nameMatches.length > 1) {
|
||||||
tabula.sortArrayOfObjects(nameMatches, 'published_at');
|
tabula.sortArrayOfObjects(nameMatches, 'published_at');
|
||||||
cb(null, nameMatches[nameMatches.length - 1]);
|
cb(null, nameMatches[nameMatches.length - 1]);
|
||||||
|
} else if (shortIdMatches.length === 1) {
|
||||||
|
cb(null, shortIdMatches[0]);
|
||||||
|
} else if (shortIdMatches.length === 0) {
|
||||||
|
cb(new Error(format(
|
||||||
|
'no image with name or shortId "%s" was found', name)));
|
||||||
|
} else {
|
||||||
|
cb(new Error(format('no image with name "%s" was found '
|
||||||
|
+ 'and "%s" is an ambiguous shortId', name)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user