diff frontends/src/jp/base.py @ 2309:c7a72b75232b

jp (shell): shell command (REPL mode), first draft: This command launch jp in REPL mode, allowing do normal jp commands with some facilities. Command can be selected with "cmd" (e.g. "cmd blog"). An argument can be fixed with "use" (e.g. "use output fancy"). Command is launched with "do", or directly with its name if it doesn't conflict with a shell command. Arguments completion is still TODO (only shell commands are completed so far).
author Goffi <goffi@goffi.org>
date Thu, 06 Jul 2017 20:28:25 +0200
parents 637886ac35f6
children eaff25529c53
line wrap: on
line diff
--- a/frontends/src/jp/base.py	Wed Jul 05 15:05:49 2017 +0200
+++ b/frontends/src/jp/base.py	Thu Jul 06 20:28:25 2017 +0200
@@ -165,6 +165,9 @@
 
         self.bridge = bridge_module.Bridge()
         self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb)
+        # _no_exit is used in shell mode because SystemExit can't
+        # catched when loop is in use
+        self._no_exit = False
 
     def _bridgeCb(self):
         self.parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -402,8 +405,8 @@
                 cls = getattr(module, class_name)
                 cls(self)
 
-    def run(self, args=None):
-        self.args = self.parser.parse_args(args)
+    def run(self, args=None, namespace=None):
+        self.args = self.parser.parse_args(args, namespace=None)
         try:
             self.args.func()
             if self._need_loop or self._auto_loop:
@@ -442,7 +445,8 @@
                 callback(*args, **kwargs)
 
         self.stop_loop()
-        sys.exit(errcode)
+        if not self._no_exit:
+            sys.exit(errcode)
 
     def check_jids(self, jids):
         """Check jids validity, transform roster name to corresponding jids