joyent/node-triton#111 want triton env --unset,-u option emit env to unset relevant envvars

This commit is contained in:
Trent Mick 2016-04-22 12:55:32 -07:00
parent de391bf013
commit a48d7629dd
6 changed files with 86 additions and 28 deletions

View File

@ -5,9 +5,11 @@ Known issues:
- `triton ssh ...` disables ssh ControlMaster to avoid issue #52. - `triton ssh ...` disables ssh ControlMaster to avoid issue #52.
## 4.10.1 (not yet released) ## 4.11.0 (not yet released)
(nothing yet) - [#111] `triton env --unset,-u` option to emit environment commands to *unset*
relevant envvars.
- Unhide `triton env` from `triton --help` output.
## 4.10.0 ## 4.10.0

View File

@ -1,9 +1,4 @@
test suite: triton create affinity support for tag matching, globs, regex
- all the commands: test/integration/cli-*.test.js
- TritonApi testing: test/integration/api-*.test.js
- more test/unit/...
sub-user support (profiles, `triton account`, env, auth)
note in README that full UUIDs is much faster in the API note in README that full UUIDs is much faster in the API

View File

@ -207,8 +207,9 @@ function CLI() {
}, },
helpSubcmds: [ helpSubcmds: [
'help', 'help',
'completion',
'profile', 'profile',
'env',
'completion',
{ group: 'Instances (aka VMs/Machines/Containers)' }, { group: 'Instances (aka VMs/Machines/Containers)' },
'instance', 'instance',
'instances', 'instances',

View File

@ -45,6 +45,9 @@ function do_env(subcmd, opts, args, cb) {
shortOpts += 's'; shortOpts += 's';
clientTypes.push('smartdc'); clientTypes.push('smartdc');
} }
if (opts.unset) {
shortOpts += 'u';
}
if (clientTypes.length === 0) { if (clientTypes.length === 0) {
explicit = false; explicit = false;
clientTypes = allClientTypes; clientTypes = allClientTypes;
@ -68,7 +71,20 @@ function do_env(subcmd, opts, args, cb) {
clientTypes.forEach(function (clientType) { clientTypes.forEach(function (clientType) {
switch (clientType) { switch (clientType) {
case 'triton': case 'triton':
p('export TRITON_PROFILE="%s"', profile.name); if (opts.unset) {
[
'TRITON_PROFILE',
'TRITON_URL',
'TRITON_ACCOUNT',
'TRITON_USER',
'TRITON_KEY_ID',
'TRITON_TLS_INSECURE'
].forEach(function (key) {
p('unset %s', key);
});
} else {
p('export TRITON_PROFILE="%s"', profile.name);
}
break; break;
case 'docker': case 'docker':
var setupJson = path.resolve(self.configDir, 'docker', var setupJson = path.resolve(self.configDir, 'docker',
@ -85,12 +101,21 @@ function do_env(subcmd, opts, args, cb) {
} }
Object.keys(setup.env).forEach(function (key) { Object.keys(setup.env).forEach(function (key) {
var val = setup.env[key]; var val = setup.env[key];
if (val === null) { if (opts.unset || val === null) {
p('unset %s', key); p('unset %s', key);
} else { } else {
p('export %s=%s', key, val); p('export %s=%s', key, val);
} }
}); });
} else if (opts.unset) {
[
'DOCKER_HOST',
'DOCKER_CERT_PATH',
'DOCKER_TLS_VERIFY',
'COMPOSE_HTTP_TIMEOUT'
].forEach(function (key) {
p('unset %s', key);
});
} else if (explicit) { } else if (explicit) {
cb(new errors.ConfigError(format('could not find Docker ' cb(new errors.ConfigError(format('could not find Docker '
+ 'environment setup for profile "%s":\n Run `triton ' + 'environment setup for profile "%s":\n Run `triton '
@ -99,18 +124,30 @@ function do_env(subcmd, opts, args, cb) {
} }
break; break;
case 'smartdc': case 'smartdc':
p('export SDC_URL="%s"', profile.url); if (opts.unset) {
p('export SDC_ACCOUNT="%s"', profile.account); [
if (profile.user) { 'SDC_URL',
p('export SDC_USER="%s"', profile.user); 'SDC_ACCOUNT',
'SDC_USER',
'SDC_KEY_ID',
'SDC_TESTING'
].forEach(function (key) {
p('unset %s', key);
});
} else { } else {
p('unset SDC_USER'); p('export SDC_URL="%s"', profile.url);
} p('export SDC_ACCOUNT="%s"', profile.account);
p('export SDC_KEY_ID="%s"', profile.keyId); if (profile.user) {
if (profile.insecure) { p('export SDC_USER="%s"', profile.user);
p('export SDC_TESTING="%s"', profile.insecure); } else {
} else { p('unset SDC_USER');
p('unset SDC_TESTING'); }
p('export SDC_KEY_ID="%s"', profile.keyId);
if (profile.insecure) {
p('export SDC_TESTING="%s"', profile.insecure);
} else {
p('unset SDC_TESTING');
}
} }
break; break;
default: default:
@ -132,6 +169,9 @@ do_env.options = [
type: 'bool', type: 'bool',
help: 'Show this help.' help: 'Show this help.'
}, },
{
group: ''
},
{ {
names: ['triton', 't'], names: ['triton', 't'],
type: 'bool', type: 'bool',
@ -147,13 +187,21 @@ do_env.options = [
names: ['smartdc', 's'], names: ['smartdc', 's'],
type: 'bool', type: 'bool',
help: 'Emit environment for node-smartdc (i.e. the "SDC_*" variables).' help: 'Emit environment for node-smartdc (i.e. the "SDC_*" variables).'
},
{
group: ''
},
{
names: ['unset', 'u'],
type: 'bool',
help: 'Emit environment to *unset* the relevant environment variables.'
} }
]; ];
// TODO: support env for docker usage. // 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 commands to setup environment.',
'', '',
'Supported "clients" here are: node-smartdc (i.e. the `sdc-*` tools),', 'Supported "clients" here are: node-smartdc (i.e. the `sdc-*` tools),',
'and node-triton itself. By default this emits the environment for all', 'and node-triton itself. By default this emits the environment for all',
@ -162,11 +210,21 @@ do_env.help = [
'Usage:', 'Usage:',
' {{name}} env [PROFILE]', ' {{name}} env [PROFILE]',
'', '',
'{{options}}' '{{options}}',
'If no options are given, environment variables are emitted for all clients.',
'If PROFILE is not given, the current profile is used.',
'',
'The following Bash function can be added to one\'s "~/.bashrc" to quickly',
'change between Triton profiles:',
' triton-select () { eval "$(triton env $1)"; }',
'for example:',
' $ triton-select west1',
' $ triton profile get | grep name',
' name: west1',
' $ triton-select east1',
' $ triton profile get | grep name',
' name: east1'
/* END JSSTYLED */ /* END JSSTYLED */
].join('\n'); ].join('\n');
do_env.hidden = true;
module.exports = do_env; module.exports = do_env;

View File

@ -1,7 +1,7 @@
{ {
"name": "triton", "name": "triton",
"description": "Joyent Triton CLI and client (https://www.joyent.com/triton)", "description": "Joyent Triton CLI and client (https://www.joyent.com/triton)",
"version": "4.10.1", "version": "4.11.0",
"author": "Joyent (joyent.com)", "author": "Joyent (joyent.com)",
"dependencies": { "dependencies": {
"assert-plus": "0.2.0", "assert-plus": "0.2.0",

View File

@ -28,6 +28,8 @@ var subs = [
['profile create'], ['profile create'],
['profile edit'], ['profile edit'],
['profile delete', 'profile rm'], ['profile delete', 'profile rm'],
['env'],
['completion'],
['account'], ['account'],
['account get'], ['account get'],
['account update'], ['account update'],