async def app(ctx: commands.Context, *argv: str): global DRIVER output_list = [] with contextlib.redirect_stdout(StringIO()) as o: with contextlib.redirect_stderr(o): try: if DRIVER is None: parser = Parser(prog="$app") DRIVER = runtime.AsyncDriver(parser=parser) await DRIVER.run(argv, module=sys.modules[__name__], debug=True) else: await DRIVER._run(argv, debug=True) except Exit as e: logger.debug("exit: %r", e) output = o.getvalue() if output.strip(): output_list.append(output) new_line = "\n" if output_list: await ctx.send(f"""\ ``` {new_line.join(output_list).strip(new_line)} ```""")
async def run(self, ctx: commands.Context) -> None: text = ctx.message.content argv = runtime.parse(text, name=self.command_name) with runtime.handle() as output_list: if self.driver is None: self.driver = cli_runtime.AsyncDriver(parser=self.parser) await self.driver.run(argv, module=self.module, debug=self.debug) else: await self.driver._run(argv, debug=self.debug) if output_list: new_line = "\n" await ctx.send(f"""\ ``` {new_line.join(output_list).strip(new_line)} ```""")
async def app(ctx: commands.Context): global DRIVER text = ctx.message.content argv = runtime.parse(text, name="$app") with runtime.handle() as output_list: if DRIVER is None: parser = runtime.ExitExceptionParser(prog="$app") DRIVER = cli_runtime.AsyncDriver(parser=parser) await DRIVER.run(argv, module=sys.modules[__name__], debug=True) else: await DRIVER._run(argv, debug=True) new_line = "\n" if output_list: await ctx.send( f"""\ ``` {new_line.join(output_list).strip(new_line)} ```""" )
async def app(ctx: commands.Context): global DRIVER text = ctx.message.content argv = shlex.split(text.split("$app", 1)[1], posix=True) output_list = [] with contextlib.redirect_stdout(StringIO()) as o: with contextlib.redirect_stderr(o): try: if DRIVER is None: parser = Parser(prog="$app") DRIVER = runtime.AsyncDriver(parser=parser) await DRIVER.run(argv, module=sys.modules[__name__], debug=True) else: await DRIVER._run(argv, debug=True) except Exit as e: logger.debug("exit: %r", e) except Exception: import traceback tb = traceback.format_exc() print(tb, file=o) output = o.getvalue() if output.strip(): output_list.append(output) new_line = "\n" if output_list: await ctx.send(f"""\ ``` {new_line.join(output_list).strip(new_line)} ```""")