catch-22: Controlling force_terminal value based on command line arguments #484
-
One catch-33 issue that I had around Console initialization is around determining the force_terminal value for command line applications that allow user to override its value using command line arguments. Console instance needs to be instantiated as soon as possible in order to be able to display various messages, including those related to configuration file loading or command line arguments. Still, in order to allow user to enable or disable the terminal, you first need to reach the point where config file was loaded and command line parameters were parse. At this point you already instantiated the console... I am not yet sure how to address this issue, but I am wondering if it would be acceptable to change the terminal value after the moment the instance was created? What other options do we have? For new applications it would not be a big issue as I can just avoid adding any command line arguments that control it and use exclusively environment variables, as they can be checked when Console is instantiated. Still, if your application already supports command line arguments or config items, you do not want to introduce regressions, another solution is needed. If needed I could also include some link to current code. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can replace a reference to the Console instance once you have read the conf, but that wouldn't help if you have already imported a reference in an other module. You can't really reconfigure a Console instance via the API, but something like this should work: from my_project import console
def reconfigure_console(*args, **kwargs):
global console
new_console = Console(*args, **kwargs)
console.__dict__ = new_console.__dict__ It's a bit of a hack, but I can't see it breaking anything. |
Beta Was this translation helpful? Give feedback.
You can replace a reference to the Console instance once you have read the conf, but that wouldn't help if you have already imported a reference in an other module.
You can't really reconfigure a Console instance via the API, but something like this should work:
It's a bit of a hack, but I can't see it breaking anything.