Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyword arguments to typer.main.run() #648

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
53 changes: 51 additions & 2 deletions typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,56 @@ def wrapper(ctx: click.Context, args: List[str], incomplete: Optional[str]) -> A
return wrapper


def run(function: Callable[..., Any]) -> None:
app = Typer(add_completion=False)
def run(
function: Callable[..., Any],
name: Optional[str] = Default(None),
cls: Optional[Type[TyperGroup]] = Default(None),
invoke_without_command: bool = Default(False),
no_args_is_help: bool = Default(False),
subcommand_metavar: Optional[str] = Default(None),
chain: bool = Default(False),
result_callback: Optional[Callable[..., Any]] = Default(None),
# Command
context_settings: Optional[Dict[Any, Any]] = Default(None),
callback: Optional[Callable[..., Any]] = Default(None),
help: Optional[str] = Default(None),
epilog: Optional[str] = Default(None),
short_help: Optional[str] = Default(None),
options_metavar: str = Default("[OPTIONS]"),
add_help_option: bool = Default(True),
hidden: bool = Default(False),
deprecated: bool = Default(False),
add_completion: bool = False,
# Rich settings
rich_markup_mode: Optional[MarkupMode] = None,
rich_help_panel: Optional[Union[str, None]] = Default(None),
pretty_exceptions_enable: bool = True,
pretty_exceptions_show_locals: bool = True,
pretty_exceptions_short: bool = True,
) -> None:
app = Typer(
name=name,
cls=cls,
invoke_without_command=invoke_without_command,
no_args_is_help=no_args_is_help,
subcommand_metavar=subcommand_metavar,
chain=chain,
result_callback=result_callback,
context_settings=context_settings,
callback=callback,
help=help,
epilog=epilog,
short_help=short_help,
options_metavar=options_metavar,
add_help_option=add_help_option,
hidden=hidden,
deprecated=deprecated,
add_completion=add_completion,
rich_markup_mode=rich_markup_mode,
rich_help_panel=rich_help_panel,
pretty_exceptions_enable=pretty_exceptions_enable,
pretty_exceptions_show_locals=pretty_exceptions_show_locals,
pretty_exceptions_short=pretty_exceptions_short,
)
app.command()(function)
app()