🎨 Improve shell experience
- more informative banner - make project singleton available via identifier `p`
This commit is contained in:
parent
35e6ddfcf5
commit
aea68b8128
1 changed files with 5 additions and 5 deletions
|
|
@ -9,7 +9,9 @@ from ohmyapi.core import scaffolding, runtime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
app = typer.Typer(help="OhMyAPI — Django-flavored FastAPI scaffolding with tightly integrated TortoiseORM.")
|
app = typer.Typer(help="OhMyAPI — Django-flavored FastAPI scaffolding with tightly integrated TortoiseORM.")
|
||||||
banner = """OhMyAPI Shell | Project: {project_name}"""
|
banner = """OhMyAPI Shell | Project: {project_name}
|
||||||
|
Find your loaded project singleton via identifier: `p`
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
|
|
@ -46,16 +48,14 @@ def shell(root: str = "."):
|
||||||
try:
|
try:
|
||||||
from IPython import start_ipython
|
from IPython import start_ipython
|
||||||
shell_vars = {
|
shell_vars = {
|
||||||
"settings": project.settings,
|
"p": project,
|
||||||
"project": Path(project_path).resolve(),
|
|
||||||
}
|
}
|
||||||
from traitlets.config.loader import Config
|
from traitlets.config.loader import Config
|
||||||
c = Config()
|
c = Config()
|
||||||
c.TerminalIPythonApp.display_banner = True
|
c.TerminalIPythonApp.display_banner = True
|
||||||
c.TerminalInteractiveShell.banner1 = banner.format(**{
|
c.TerminalInteractiveShell.banner2 = banner.format(**{
|
||||||
"project_name": f"{f'{project.settings.PROJECT_NAME} ' if getattr(project.settings, 'PROJECT_NAME', '') else ''}[{Path(project_path).resolve()}]",
|
"project_name": f"{f'{project.settings.PROJECT_NAME} ' if getattr(project.settings, 'PROJECT_NAME', '') else ''}[{Path(project_path).resolve()}]",
|
||||||
})
|
})
|
||||||
c.TerminalInteractiveShell.banner2 = " "
|
|
||||||
start_ipython(argv=[], user_ns=shell_vars, config=c)
|
start_ipython(argv=[], user_ns=shell_vars, config=c)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
typer.echo("IPython is not installed. Falling back to built-in Python shell.")
|
typer.echo("IPython is not installed. Falling back to built-in Python shell.")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue