From 15ff6aedf48a2b4d935d83ae861818c0e3c75dc1 Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 8 Sep 2017 07:58:10 +0200 Subject: [PATCH] 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 --- frontends/src/jp/arg_tools.py | 2 +- frontends/src/jp/cmd_shell.py | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/frontends/src/jp/arg_tools.py b/frontends/src/jp/arg_tools.py index 5cee77e1..6b091450 100644 --- a/frontends/src/jp/arg_tools.py +++ b/frontends/src/jp/arg_tools.py @@ -89,7 +89,7 @@ def get_use_args(host, args, use, verbose=False, parser=None): value=escape(value))) else: if verbose: - host.disp(_(u'arg {name}={value} set (in USE)').format(name=arg, value=escape(value))) + host.disp(_(u'arg {name}={value} (in USE)').format(name=arg, value=escape(value))) if not action.option_strings: pos_args.append(value) else: diff --git a/frontends/src/jp/cmd_shell.py b/frontends/src/jp/cmd_shell.py index 99052875..29917aa0 100644 --- a/frontends/src/jp/cmd_shell.py +++ b/frontends/src/jp/cmd_shell.py @@ -34,7 +34,7 @@ INTRO = _(u"""Welcome to {app_name} shell, the Salut à Toi shell ! This enrironment helps you using several {app_name} commands with similar parameters. -To quit, just enter "quit" or press C-c. +To quit, just enter "quit" or press C-d. Enter "help" or "?" to know what to do """).format(app_name = C.APP_NAME) @@ -122,6 +122,8 @@ class Shell(base.CommandBase, cmd.Cmd): will launch the command with args on the line (i.e. will launch do [args]) """ + if args=='EOF': + self.do_quit('') self.do_do(args) def do_help(self, args): @@ -180,11 +182,25 @@ class Shell(base.CommandBase, cmd.Cmd): def do_do(self, args): """lauch a command""" args = self.parse_args(args) + if (self._not_default_profile and + not '-p' in args and + not '--profile' in args and + not 'profile' in self.use): + # profile is not specified and we are not using the default profile + # so we need to add it in arguments to use current user profile + if self.verbose: + self.disp(_(u'arg profile={profile} (logged profile)').format(profile=self.profile)) + use = self.use.copy() + use['profile'] = self.profile + else: + use = self.use + + # args may be modified by use_args # to remove subparsers from it parser_args, use_args = arg_tools.get_use_args(self.host, args, - self.use, + use, verbose=self.verbose, parser=self._cur_parser ) @@ -238,6 +254,8 @@ class Shell(base.CommandBase, cmd.Cmd): self.do_quit(args) def start(self): + default_profile = self.host.bridge.profileNameGet(C.PROF_KEY_DEFAULT) + self._not_default_profile = self.profile != default_profile self.path = [] self._cur_parser = self.host.parser self.use = {}