I would like to capture the Python-click Console output in order to write it into a logfile for example when an argument was not specified.
Is there a way I can capture the console output from click.
I have tried it with this code:
@click.group(cls=DefaultGroup, default="subcmd", default_if_no_args=True)
@click.option('--verbose', '-v', is_flag=True, help="Increase output verbosity level")
@click.pass_context
def main(ctx, verbose):
ctx.obj["verbose"] = verbose
lines = click.get_text_stream("stderr").readlines()
#further code to write the stderr lines into to the logfile
@main.command("subcmd", context_settings=dict(allow_extra_args=True,))
@click.argument('arg1', required=True, default="Value1", type=click.Choice(['Value1', 'Value2']))
@click.argument('arg2', required=True)
@click.pass_context
def subCmd(ctx, arg1, arg2):
pass
if __name__ == "__main__":
main(obj={})
Unfortunately, this gives me an error
Exception has occurred: UnsupportedOperation
not readable
question from:
https://stackoverflow.com/questions/65848994/python-click-console-output-to-logfile 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…