FergusFettes / typer-shell

Simple wrapper around the Typer library for making beautiful shells/REPLs for fast command-line prototyping with Python.
GNU General Public License v3.0
10 stars 2 forks source link

Missing `on_finished` callable #9

Closed ahussey-redhat closed 3 weeks ago

ahussey-redhat commented 2 months ago

click-shell takes an option on_finished callable, which enables it to run cleanup tasks.

It would be great if this could also be added to typer-shell :) https://github.com/clarkperkins/click-shell/blob/main/docs/usage.rst

on_finished - a callable that will be called when the shell exits. You can use it to clean up any resources that may need cleaning up.
ahussey-redhat commented 2 months ago

I'm guessing the solution would be to add another argument here https://github.com/FergusFettes/typer-shell/blob/f6c301738365e90c90cefe54bd3c4676839daae5/typer_shell/typer_shell.py#L16

def make_typer_shell(
        prompt: str = ">> ",
        on_finished: Callable = lambda ctx: None,
        intro: str = "\n Welcome to typer-shell! Type help to see commands.\n",
        obj: Optional[object] = None,
        params: Optional[dict] = None,
        params_path: Optional[Path] = None,
        launch: Callable = lambda ctx: None,
)
...
shell = make_click_shell(ctx, prompt=prompt, intro=intro)
shell.on_finished: Optional[Callable[[click.Context], None]] = on_finished

Based on the click-shell implementation. I could be way off though

FergusFettes commented 3 weeks ago

Hey, sorry for the slow reply. I have added this, your suggestion was pretty close! Should be in the pypi shortly, let me know if there is an issue, I would be quicker next time ;)

ahussey-redhat commented 3 weeks ago

Thanks for implementing this. I really appreciate it! :)