I'm working on a CLI for my project. I want it to work in a way similar to an interpreter. For example, once I initialise, I can proceed with other commands.
Consider a sandbox examble:
import typer
app = typer.Typer()
@app.command()
def init():
global x
x = 5
@app.command()
def print_():
print(x)
if __name__ == "__main__":
app()
This works if I replace app() with init(); print_(). However, if I use a CLI (in my case it is Windows Command Prompt), the script terminates after the first command, so after script init (let the script be named as script.py) I cannot run script print- as the variable x is not defined anymore.
How can I make it work? Is it possible for a CLI to keep script running and waiting for further commands? Other instruments apart from typer can also be put forward.