comparison frontends/src/jp/cmd_shell.py @ 2354:5129a0506739

jp (shell): fixed use of profile + added EOF handling: - main profile (i.e. the one specified on command line when invocating "jp shell") was not used. It is now added to arguments if the value is not overriden on command line or in use - EOF (i.e. when user press C-d) is now understood as "quit" command
author Goffi <goffi@goffi.org>
date Fri, 08 Sep 2017 07:58:10 +0200
parents f4e05600577b
children 8b37a62336c3
comparison
equal deleted inserted replaced
2353:ebc0dfe9c0ca 2354:5129a0506739
32 __commands__ = ["Shell"] 32 __commands__ = ["Shell"]
33 INTRO = _(u"""Welcome to {app_name} shell, the Salut à Toi shell ! 33 INTRO = _(u"""Welcome to {app_name} shell, the Salut à Toi shell !
34 34
35 This enrironment helps you using several {app_name} commands with similar parameters. 35 This enrironment helps you using several {app_name} commands with similar parameters.
36 36
37 To quit, just enter "quit" or press C-c. 37 To quit, just enter "quit" or press C-d.
38 Enter "help" or "?" to know what to do 38 Enter "help" or "?" to know what to do
39 """).format(app_name = C.APP_NAME) 39 """).format(app_name = C.APP_NAME)
40 40
41 41
42 class Shell(base.CommandBase, cmd.Cmd): 42 class Shell(base.CommandBase, cmd.Cmd):
120 """called when no shell command is recognized 120 """called when no shell command is recognized
121 121
122 will launch the command with args on the line 122 will launch the command with args on the line
123 (i.e. will launch do [args]) 123 (i.e. will launch do [args])
124 """ 124 """
125 if args=='EOF':
126 self.do_quit('')
125 self.do_do(args) 127 self.do_do(args)
126 128
127 def do_help(self, args): 129 def do_help(self, args):
128 """show help message""" 130 """show help message"""
129 if not args: 131 if not args:
178 self.run_cmd(args, external=True) 180 self.run_cmd(args, external=True)
179 181
180 def do_do(self, args): 182 def do_do(self, args):
181 """lauch a command""" 183 """lauch a command"""
182 args = self.parse_args(args) 184 args = self.parse_args(args)
185 if (self._not_default_profile and
186 not '-p' in args and
187 not '--profile' in args and
188 not 'profile' in self.use):
189 # profile is not specified and we are not using the default profile
190 # so we need to add it in arguments to use current user profile
191 if self.verbose:
192 self.disp(_(u'arg profile={profile} (logged profile)').format(profile=self.profile))
193 use = self.use.copy()
194 use['profile'] = self.profile
195 else:
196 use = self.use
197
198
183 # args may be modified by use_args 199 # args may be modified by use_args
184 # to remove subparsers from it 200 # to remove subparsers from it
185 parser_args, use_args = arg_tools.get_use_args(self.host, 201 parser_args, use_args = arg_tools.get_use_args(self.host,
186 args, 202 args,
187 self.use, 203 use,
188 verbose=self.verbose, 204 verbose=self.verbose,
189 parser=self._cur_parser 205 parser=self._cur_parser
190 ) 206 )
191 cmd_args = self.path + parser_args + use_args 207 cmd_args = self.path + parser_args + use_args
192 self.run_cmd(cmd_args) 208 self.run_cmd(cmd_args)
236 def do_exit(self, args): 252 def do_exit(self, args):
237 u"""alias for quit""" 253 u"""alias for quit"""
238 self.do_quit(args) 254 self.do_quit(args)
239 255
240 def start(self): 256 def start(self):
257 default_profile = self.host.bridge.profileNameGet(C.PROF_KEY_DEFAULT)
258 self._not_default_profile = self.profile != default_profile
241 self.path = [] 259 self.path = []
242 self._cur_parser = self.host.parser 260 self._cur_parser = self.host.parser
243 self.use = {} 261 self.use = {}
244 self.verbose = False 262 self.verbose = False
245 self.update_path() 263 self.update_path()