From a62ba15858ff7e4df6a68a04a59541303d1eca67 Mon Sep 17 00:00:00 2001 From: Adam Groszer Date: Wed, 10 Jul 2024 22:10:56 +0200 Subject: [PATCH 1/2] fix fstring --- icli/lang.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/icli/lang.py b/icli/lang.py index 1645bc2..47fde91 100644 --- a/icli/lang.py +++ b/icli/lang.py @@ -3266,7 +3266,7 @@ def populateSymbolDetails(target): if df.empty: logger.info( "{}No open orders exist for client id {}!", - f"[{", ".join(sorted(self.symbols))}] " if self.symbols else "", + f"[{', '.join(sorted(self.symbols))}] " if self.symbols else "", ICLI_CLIENT_ID, ) return From aa351b966e862cd5f3bdb88d8970ff003e145355 Mon Sep 17 00:00:00 2001 From: Adam Groszer Date: Sun, 28 Jul 2024 11:27:04 +0200 Subject: [PATCH 2/2] just execute the given args as as command(s) and exit --- icli/__main__.py | 7 ++++++- icli/cli.py | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/icli/__main__.py b/icli/__main__.py index e3cbf53..d2b963e 100755 --- a/icli/__main__.py +++ b/icli/__main__.py @@ -43,7 +43,12 @@ async def initcli(): # patch entire application with prompt-toolkit-compatible stdout with patch_stdout(raw=True): try: - await app.runall() + if len(sys.argv) > 1: + # just add quotes to the first arg to get 1 parameter + cmds = sys.argv[1] + else: + cmds = None + await app.runall(cmds) except (SystemExit, EOFError): # known-good exit condition pass diff --git a/icli/cli.py b/icli/cli.py index 48c46b2..7869467 100644 --- a/icli/cli.py +++ b/icli/cli.py @@ -3019,19 +3019,45 @@ def buildRunnablesFromCommandRequest(self, text1): return runnables - async def runall(self): + async def runall(self, cmds=None): logger.info( "Using ib_async version: {} :: {}", ib_async.version.__version__, ib_async.version.__version_info__, ) await self.prepare() - while not self.exiting: - try: - await self.dorepl() - except: - logger.exception("Uncaught exception in repl? Restarting...") - continue + + if cmds is not None: + # just execute the given args as as command(s) and exit + + # 'runnables' is the list of all commands to run after we collect them + runnables = self.buildRunnablesFromCommandRequest(cmds) + + # if no commands, just draw the prompt again + if not runnables: + return + + if len(runnables) == 1: + # if only one command, don't run with an extra Timer() report like we do below + # with multiple commands (individual commands always report their individual timing) + await runnables[0] + else: + # only show the "All commands" timer if we have multiple commands to run + with Timer("All commands"): + for run in runnables: + try: + # run a COLLECTIVE COMMAND GROUP we previously created + await run + except: + logger.exception("[{}] Runnable failed?", run) + self.exiting = True + else: + while not self.exiting: + try: + await self.dorepl() + except: + logger.exception("Uncaught exception in repl? Restarting...") + continue async def prepare(self): # Setup...