Metadata-Version: 2.1
Name: fastapi-fastcli
Version: 0.1.7
Summary: FastAPI CLI
Author: Jack Zhai
Author-email: zhaijiawei0828@gmail.com
Requires-Python: >=3.8,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Dist: fastapi (>=0.100)
Requires-Dist: rich (>=13)
Requires-Dist: typer (>=0.9.0)
Requires-Dist: uvicorn (>=0.23)
Description-Content-Type: text/markdown

# Fastapi CLI

在使用 FastAPI 前，我个人使用 Flask 居多，比较喜欢 Flask 的 CLI，使用起来比较方便，这个项目就是解决 FastAPI 没有 CLI 的问题

使用它自动加载项目中已有的 Typer 实例

#### 使用前

假设我们的 CLI 代码在下面的路径**app/cli/**init**.py**

```python
import typer

app = typer.Typer()

@app.command()
def version():
    return "1.0.0"
```

为了方便执行，我们需要在项目根目录新增一个入口文件如**cli.py**并添加下面的内容

```python
from app.cli import app

if __name__ == __main__:
    app()
```

最后执行

```shell
python cli.py --help
```

#### 使用后

使用 fastcli 由于 app.cli:app 在默认路径下，因此会自动加载，我们只需要运行下面的命令即可

```shell
fastcli --help
```

## 安装使用

#### 安装

```shell
pip install fastapi-fastcli

# 安装TAB自动补全
fastcli --install-completion
```

#### 查看路由列表

```shell
fastcli routes
```

#### 启动 FastAPI 应用

```shell
fastcli run
```

在运行时所在的目录 查找下列路径

```txt
- app.commands:app
- app.cli:app
- cli:app
- main:cli
- manage:cli
- app:cli
```

你也通过环境变量 **TYPER_APP**指定

功能

- 查看路由
- 启动 FastAPI 应用（uvicron）

