This function converts a given function to a CLI application with `Typer()` and executes it. ## Example ```python import typer def main(name: str): print(f"Hello {name}") if __name__ == "__main__": typer.run(main) ```
(
function: Annotated[
Callable[..., Any],
Doc(
"""
The function that should power this CLI application.
"""
),
],
)
| 1889 | |
| 1890 | |
| 1891 | def run( |
| 1892 | function: Annotated[ |
| 1893 | Callable[..., Any], |
| 1894 | Doc( |
| 1895 | class="st">""" |
| 1896 | The function that should power this CLI application. |
| 1897 | class="st">""" |
| 1898 | ), |
| 1899 | ], |
| 1900 | ) -> None: |
| 1901 | class="st">""" |
| 1902 | This function converts a given function to a CLI application with `Typer()` and executes it. |
| 1903 | |
| 1904 | class="cm">## Example |
| 1905 | |
| 1906 | ```python |
| 1907 | import typer |
| 1908 | |
| 1909 | def main(name: str): |
| 1910 | print(fclass="st">"Hello {name}") |
| 1911 | |
| 1912 | if __name__ == class="st">"__main__": |
| 1913 | typer.run(main) |
| 1914 | ``` |
| 1915 | class="st">""" |
| 1916 | app = Typer(add_completion=False) |
| 1917 | app.command()(function) |
| 1918 | app() |
| 1919 | |
| 1920 | |
| 1921 | def _is_macos() -> bool: |