Add output of get_usage() to get_info_dict()
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
首先跟踪 Click 的 command 和 group API 中的 get_info_dict() 与 get_usage(),然后检查返回的 info-dict 结构以及相关 issue #2762。完成的标准是:该 dictionary 包含 command 和嵌套 command 的 usage 输出,且不需要使用文档中所述的 workaround。
由索引模型根据 Issue 内容生成。
描述
Context
I am generating some of my user-facing documentation using get_info_dict(), and was looking for a way to automate the usage as well without having to hardcode it in the docstrings.
Potential solution
Using the calls of get_info_dict() to add a usage key with the value being the output of get_usage().
Other relevant issues: #2762
Workaround
For now I'm using get_info_dict(), then looping through the context to get groups and commands, and using get_usage() on each, then adding it to that dictionary. The code looks something like this (with the for loop matching the structure of my CLI):
info = ctx.to_info_dict()
for cmd_n1 in ctx.command.list_commands(ctx):
cmd2 = ctx.command.get_command(ctx, cmd_n1)
sub_ctx = ctx._make_sub_context(cmd2)
usage = cmd2.get_usage(sub_ctx).replace("Usage: ", "")
info["command"]["commands"][cmd_n1]["usage"] = usage
if isinstance(cmd2, click.Group):
# Groups
for cmd_n2 in cmd2.list_commands(ctx):
cmd3 = cmd2.get_command(ctx, cmd_n2)
sub_ctx3 = sub_ctx._make_sub_context(cmd3)
usage = cmd3.get_usage(sub_ctx3).replace("Usage: ", "")
info["command"]["commands"][cmd_n1]["commands"][cmd_n2]["usage"] = usage
- 主要语言
- Python
- 星标
- 17.8k
- 派生
- 3.3k
- 平均合并
- 3 天 3 小时
- 30 天内合并 PR
- 13
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pallets/click 的其他 Issue
-
`show_envvar=True` Drops Environment Variable from Error Messages When Using `auto_envvar_prefix`未关闭
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
More private utilities that need to be marked and public api deprecated可能重新可做 关联的 PR 已关闭且未合并。 未关闭typing
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
Automatically append ellipsis (`...`) to metavars when `multiple=True` in options可能已有人在做 @SparshGarg999 于 89 天前认领。 未关闭help output
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
`HelpFormatter.write_usage` breaks options at a hyphen可能已有人在做 @kdeldycke 于 9 天前认领。 未关闭help output
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
Add glossary of terms to click reference docs可能已有人在做 @rohitbarhate111-commits 于 56 天前认领。 未关闭docs
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
相似的 Issue
-
needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
gke-labs/kube-agents#5671 ·
维护者通常 1 天内回复
-
documentation next-release v0.9.6
难度 1/5 1 小时以内 新手友好度 88/100
khuisman/mcp-gee-sweet#1446 ·
维护者通常 1 天内回复
-
model:sonnet runtime:claude security size:S
难度 2/5 1-3 小时 新手友好度 75/100
FootprintAI/Containarium#3671 ·
维护者通常 1 天内回复
-
HolidayBase: reassigning `language` does not re-initialize translations or re-populate holidays可能已有人在做 @shikhabhadoria 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
vacanza/holidays#4116 · 1 条评论 ·
维护者通常 1 天内回复
-
bug CLI exec
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复