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).
This commit is contained in:
Goffi 2017-07-06 20:28:25 +02:00
commit 6672bfc57b

View file

@ -165,6 +165,9 @@ class Jp(object):
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 @@ class Jp(object):
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 @@ class Jp(object):
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