add 'triton env -t'

This commit is contained in:
Trent Mick 2016-01-12 10:27:46 -08:00
parent 91ca036fbe
commit 9fbb2006bc
3 changed files with 57 additions and 31 deletions

View File

@ -2,7 +2,11 @@
## 4.0.1 (not yet released) ## 4.0.1 (not yet released)
(nothing yet) - Add `triton env -t` to be able to emit a shell environment to configure `triton` itself.
This allows one to have the following Bash function to select a Triton profile for
`triton` and node-smartdc tooling:
function triton-select { eval $(triton env $1); }
## 4.0.0 ## 4.0.0

View File

@ -28,9 +28,16 @@ function do_env(subcmd, opts, args, cb) {
} }
var profileName = args[0] || this.tritonapi.profile.name; var profileName = args[0] || this.tritonapi.profile.name;
var clientType = 'smartdc'; var allClientTypes = ['smartdc', 'triton'];
var clientTypes = [];
if (opts.smartdc) { if (opts.smartdc) {
clientType = 'smartdc'; clientTypes.push('smartdc');
}
if (opts.triton) {
clientTypes.push('triton');
}
if (clientTypes.length === 0) {
clientTypes = allClientTypes;
} }
try { try {
@ -46,8 +53,15 @@ function do_env(subcmd, opts, args, cb) {
} }
var p = console.log; var p = console.log;
var shortOpts = '';
clientTypes.forEach(function (clientType) {
switch (clientType) { switch (clientType) {
case 'triton':
shortOpts += 't';
p('export TRITON_PROFILE="%s"', profile.name);
break;
case 'smartdc': case 'smartdc':
shortOpts += 's';
p('export SDC_URL="%s"', profile.url); p('export SDC_URL="%s"', profile.url);
p('export SDC_ACCOUNT="%s"', profile.account); p('export SDC_ACCOUNT="%s"', profile.account);
if (profile.user) { if (profile.user) {
@ -61,13 +75,16 @@ function do_env(subcmd, opts, args, cb) {
} else { } else {
p('unset SDC_TESTING'); p('unset SDC_TESTING');
} }
p('# Run this command to configure your shell:');
p('# eval "$(triton env -s %s)"', profile.name);
break; break;
default: default:
return cb(new errors.InternalError( return cb(new errors.InternalError(
'unknown clientType: ' + clientType)); 'unknown clientType: ' + clientType));
} }
});
p('# Run this command to configure your shell:');
p('# eval "$(triton env%s %s)"',
(shortOpts ? ' -'+shortOpts : ''), profile.name);
} }
do_env.options = [ do_env.options = [
@ -79,20 +96,24 @@ do_env.options = [
{ {
names: ['smartdc', 's'], names: ['smartdc', 's'],
type: 'bool', type: 'bool',
help: 'Emit environment commands for node-smartdc.' help: 'Emit environment for node-smartdc (i.e. the "SDC_*" variables).'
},
{
names: ['triton', 't'],
type: 'bool',
help: 'Emit environment commands for node-triton itself (i.e. the ' +
'"TRITON_PROFILE" variable).'
} }
]; ];
// TODO: support env for docker usage.
do_env.help = [ do_env.help = [
/* BEGIN JSSTYLED */ /* BEGIN JSSTYLED */
'Emit shell environment commands to setup clients for a particular CLI profile.', 'Emit shell environment commands to setup clients for a particular CLI profile.',
'', '',
'Supported "clients" here are: node-smartdc (the `sdc-*` tools).', 'Supported "clients" here are: node-smartdc (i.e. the `sdc-*` tools),',
'TODO: support for `triton` and `docker`.', 'and node-triton itself. By default this emits the environment for all',
'', 'supported tools. Use options to be specific.',
'Note: By default this *currently* emits the environment for node-smartdc.',
'However, automated usage should use `-s` to guaratee that. The default',
'might change',
'', '',
'Usage:', 'Usage:',
' {{name}} env [PROFILE]', ' {{name}} env [PROFILE]',

View File

@ -370,6 +370,7 @@ TritonApi.prototype.getImage = function getImage(opts, cb) {
if (version) { if (version) {
listOpts.name = name; listOpts.name = name;
listOpts.version = version; listOpts.version = version;
// XXX This is bogus now?
listOpts.useCache = opts.useCache; listOpts.useCache = opts.useCache;
} }
this.cloudapi.listImages(listOpts, function (err, imgs) { this.cloudapi.listImages(listOpts, function (err, imgs) {