You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Typer命令行工具自动补全功能无法启用问题求助

Typer CLI应用自动补全失效问题

刚接触Typer,开发了一个简单的CLI应用,终端按下[TAB]无法触发自动补全功能。应用本身可正常运行,但补全功能完全失效。

项目结构

vinicius.ferreira@FVFFPG4VQ6L4 dev-env % tree
.
├── README.md
├── dev_env
│   ├── __init__.py
│   ├── main.py
│   ├── services.py
│   ├── team_product1.py
│   └── team_product2.py
├── dist
│   ├── dev_env-0.1.2-py3-none-any.whl
│   ├── dev_env-0.1.2.tar.gz
├── poetry.lock
├── pyproject.toml
└── tests
    └── __init__.py

3 directories, 11 files

代码文件内容

main.py

import typer

from . import team_product1
from . import team_product2
from . import services

app = typer.Typer()
app.add_typer(team_product1.app, name="team_product1")
app.add_typer(team_product2.app, name="team_product2")
app.add_typer(services.app, name="services")

if __name__ == "__main__":
    app()

team_product1.py

import typer

app = typer.Typer()


@app.command()
def start():
    print(f"Starting all services for Team Product 1 ...")


@app.command()
def stop():
    print(f"Stopping all services for Team Product 1 ...")


@app.command()
def destroy():
    print(f"Destroying all services for Team Product 1 ...")


if __name__ == "__main__":
    app()

team_product2.py

import typer

app = typer.Typer()


@app.command()
def start():
    print(f"Starting all services for Team Product 2 ...")


@app.command()
def stop():
    print(f"Stopping all services for Team Product 2 ...")


@app.command()
def destroy():
    print(f"Destroying all services for Team Product 2 ...")


if __name__ == "__main__":
    app()

services.py

import typer

app = typer.Typer()


@app.command()
def start(name: str):
    print(f"Starting service: {name}")


@app.command()
def stop(name: str):
    print(f"Stopping service: {name}")


@app.command()
def destroy(name: str):
    print(f"Destroying service: {name}")


if __name__ == "__main__":
    app()

已执行的操作

  1. 通过poetry build生成.whl文件,执行pip install dist/dev_env-0.1.2-py3-none-any.whl完成全局安装,CLI应用可正常运行。
  2. 执行dev-env --install-completion,终端提示"zsh completion installed in /Users/vinicius.ferreira/.zfunc/_dev-env",该文件内容如下:
#compdef dev-env

_dev_env_completion() {
  eval $(env _TYPER_COMPLETE_ARGS="${words[1,$CURRENT]}" _DEV_ENV_COMPLETE=complete_zsh dev-env)
}

compdef _dev_env_completion dev-env% 
  1. 在~/.zshrc文件末尾添加了以下配置:
zstyle ':completion:*' menu select
fpath+=~/.zfunc

疑问

注意到Typer教程显示补全应安装在/home/user/.zshrc,不清楚为何MacOS下路径不同,请问遗漏了什么配置导致自动补全失效?

内容的提问来源于stack exchange,提问作者Vini.g.fer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 20:25:01