node-triton#86 "triton profiles" should not require a current profile
This commit is contained in:
		
							parent
							
								
									e5c666a509
								
							
						
					
					
						commit
						edb28b6791
					
				| @ -2,7 +2,8 @@ | ||||
| 
 | ||||
| ## 4.4.3 (not yet released) | ||||
| 
 | ||||
| (nothing yet) | ||||
| - #86 Ensure `triton profile ls` and `triton profile set-current` work | ||||
|   when there is no current profile. | ||||
| 
 | ||||
| 
 | ||||
| ## 4.4.2 | ||||
|  | ||||
| @ -5,7 +5,7 @@ | ||||
|  */ | ||||
| 
 | ||||
| /* | ||||
|  * Copyright 2015 Joyent, Inc. | ||||
|  * Copyright 2016 Joyent, Inc. | ||||
|  */ | ||||
| 
 | ||||
| /* | ||||
| @ -101,8 +101,13 @@ function loadConfig(opts) { | ||||
|     var config = JSON.parse(c); | ||||
|     if (configPath && fs.existsSync(configPath)) { | ||||
|         c = fs.readFileSync(configPath, 'utf8'); | ||||
|         var _user = JSON.parse(c); | ||||
|         var userConfig = JSON.parse(c); | ||||
|         try { | ||||
|             var _user = JSON.parse(c); | ||||
|             var userConfig = JSON.parse(c); | ||||
|         } catch (userConfigParseErr) { | ||||
|             throw new errors.ConfigError( | ||||
|                 format('"%s" is invalid JSON', configPath)); | ||||
|         } | ||||
|         if (typeof (userConfig) !== 'object' || Array.isArray(userConfig)) { | ||||
|             throw new errors.ConfigError( | ||||
|                 format('"%s" is not an object', configPath)); | ||||
| @ -311,9 +316,14 @@ function loadProfile(opts) { | ||||
|     assert.optionalString(opts.configDir, 'opts.configDir'); | ||||
| 
 | ||||
|     if (opts.name === 'env') { | ||||
|         return _loadEnvProfile(); | ||||
|         var envProfile = _loadEnvProfile(); | ||||
|         if (!envProfile) { | ||||
|             throw new errors.ConfigError('could not load "env" profile ' | ||||
|                 + '(missing TRITON_*, or SDC_*, environment variables)'); | ||||
|         } | ||||
|         return envProfile; | ||||
|     } else if (!opts.configDir) { | ||||
|         throw new errors.TritonError( | ||||
|         throw new errors.ConfigError( | ||||
|             'cannot load profiles (other than "env") without `opts.configDir`'); | ||||
|     } else { | ||||
|         var profilePath = path.resolve( | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| /* | ||||
|  * Copyright (c) 2015 Joyent Inc. | ||||
|  * Copyright 2016 Joyent Inc. | ||||
|  * | ||||
|  * `triton profiles ...` | ||||
|  * `triton profile list ...` | ||||
|  */ | ||||
| 
 | ||||
| var tabula = require('tabula'); | ||||
| @ -38,9 +38,20 @@ function _listProfiles(cli, opts, args, cb) { | ||||
|     } | ||||
| 
 | ||||
|     // Current profile: Set 'curr' field. Apply CLI overrides.
 | ||||
|     var currProfile; | ||||
|     try { | ||||
|         currProfile = cli.tritonapi.profile; | ||||
|     } catch (err) { | ||||
|         // Ignore inability to load a profile.
 | ||||
|         if (!(err instanceof errors.ConfigError)) { | ||||
|             throw err; | ||||
|         } | ||||
|     } | ||||
|     var haveCurr = false; | ||||
|     for (i = 0; i < profiles.length; i++) { | ||||
|         var profile = profiles[i]; | ||||
|         if (profile.name === cli.tritonapi.profile.name) { | ||||
|         if (currProfile && profile.name === currProfile.name) { | ||||
|             haveCurr = true; | ||||
|             cli._applyProfileOverrides(profile); | ||||
|             if (opts.json) { | ||||
|                 profile.curr = true; | ||||
| @ -66,6 +77,10 @@ function _listProfiles(cli, opts, args, cb) { | ||||
|             columns: columns, | ||||
|             sort: sort | ||||
|         }); | ||||
|         if (!haveCurr) { | ||||
|             process.stderr.write('\nWarning: There is no current profile. ' | ||||
|                 + 'Use "triton profile set-current ..."\nto set one.\n'); | ||||
|         } | ||||
|     } | ||||
|     cb(); | ||||
| } | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| /* | ||||
|  * Copyright (c) 2015 Joyent Inc. | ||||
|  * Copyright 2016 Joyent Inc. | ||||
|  * | ||||
|  * Shared stuff for `triton profile ...` handling. | ||||
|  */ | ||||
| @ -7,7 +7,7 @@ | ||||
| var assert = require('assert-plus'); | ||||
| 
 | ||||
| var mod_config = require('../config'); | ||||
| 
 | ||||
| var errors = require('../errors'); | ||||
| 
 | ||||
| 
 | ||||
| function setCurrentProfile(opts, cb) { | ||||
| @ -25,7 +25,16 @@ function setCurrentProfile(opts, cb) { | ||||
|         return cb(err); | ||||
|     } | ||||
| 
 | ||||
|     if (cli.tritonapi.profile.name === profile.name) { | ||||
|     var currProfile; | ||||
|     try { | ||||
|         currProfile = cli.tritonapi.profile; | ||||
|     } catch (err) { | ||||
|         // Ignore inability to load a profile.
 | ||||
|         if (!(err instanceof errors.ConfigError)) { | ||||
|             throw err; | ||||
|         } | ||||
|     } | ||||
|     if (currProfile && currProfile.name === profile.name) { | ||||
|         console.log('"%s" is already the current profile', profile.name); | ||||
|         return cb(); | ||||
|     } | ||||
|  | ||||
| @ -5,7 +5,7 @@ | ||||
|  */ | ||||
| 
 | ||||
| /* | ||||
|  * Copyright (c) 2015, Joyent, Inc. | ||||
|  * Copyright 2016, Joyent, Inc. | ||||
|  */ | ||||
| 
 | ||||
| /* | ||||
| @ -47,7 +47,7 @@ test('triton account', function (tt) { | ||||
|     }); | ||||
| 
 | ||||
|     tt.test(' triton account get', function (t) { | ||||
|         h.triton('account get', function (err, stdout, stderr) { | ||||
|         h.triton('-v account get', function (err, stdout, stderr) { | ||||
|             if (h.ifErr(t, err)) | ||||
|                 return t.end(); | ||||
|             t.ok(new RegExp( | ||||
|  | ||||
		Reference in New Issue
	
	Block a user