@@ -82,9 +82,45 @@ def run(self, command, application):
82
82
p .communicate ()
83
83
84
84
85
+ class ProfileHandler (object ):
86
+ USAGE = (
87
+ '.profile # Print the current profile\n '
88
+ '.profile <name> # Change the current profile\n '
89
+ )
90
+
91
+ def __init__ (self , output = sys .stdout , err = sys .stderr ):
92
+ self ._output = output
93
+ self ._err = err
94
+
95
+ def run (self , command , application ):
96
+ """Get or set the profile.
97
+
98
+ If .profile is called with no args, the current profile
99
+ is displayed. If the .profile command is called with a
100
+ single arg, then the current profile for the application
101
+ will be set to the new value.
102
+ """
103
+ if len (command ) == 1 :
104
+ profile = application .profile
105
+ if profile is None :
106
+ self ._output .write (
107
+ "Current shell profile: no profile configured\n "
108
+ "You can change profiles using: .profile profile-name\n " )
109
+ else :
110
+ self ._output .write ("Current shell profile: %s\n " % profile )
111
+ elif len (command ) == 2 :
112
+ new_profile_name = command [1 ]
113
+ application .profile = new_profile_name
114
+ self ._output .write ("Current shell profile changed to: %s\n " %
115
+ new_profile_name )
116
+ else :
117
+ self ._err .write ("Usage:\n %s\n " % self .USAGE )
118
+
119
+
85
120
class DotCommandHandler (object ):
86
121
HANDLER_CLASSES = {
87
122
'edit' : EditHandler ,
123
+ 'profile' : ProfileHandler ,
88
124
}
89
125
90
126
def __init__ (self , output = sys .stdout , err = sys .stderr ):
@@ -163,6 +199,7 @@ def __init__(self, completer, model_completer, docs):
163
199
self .key_manager = None
164
200
self ._dot_cmd = DotCommandHandler ()
165
201
self ._env = os .environ .copy ()
202
+ self ._profile = None
166
203
167
204
# These attrs come from the config file.
168
205
self .config_obj = None
@@ -388,11 +425,12 @@ def create_cli_interface(self, display_completions_in_columns):
388
425
cli = CommandLineInterface (application = app , eventloop = loop )
389
426
return cli
390
427
391
- def on_profile_change (self , new_profile_name ):
392
- """Handler invoked when the user requests to use a new profile.
428
+ @property
429
+ def profile (self ):
430
+ return self ._profile
393
431
394
- This will inform the necessary objects to use the new profile.
395
- """
432
+ @ profile .setter
433
+ def profile ( self , new_profile_name ):
396
434
# There's only two things that need to know about new profile
397
435
# changes.
398
436
#
@@ -409,3 +447,4 @@ def on_profile_change(self, new_profile_name):
409
447
# would be worth it.
410
448
self ._env ['AWS_DEFAULT_PROFILE' ] = new_profile_name
411
449
self .completer .change_profile (new_profile_name )
450
+ self ._profile = new_profile_name
0 commit comments