Usage message is displayed when not desired.
还没有人认领这个 Issue。
评估
调研方向
使用提供的 fire_bug.py 示例重现该行为,包括链式命令和 --help。首先跟踪 Python Fire 的命令执行和帮助渲染路径;完成的标志是有效命令不再未经请求就打印帮助信息,同时无命令调用和带有 --help 的调用能够提供有用的命令信息。
由索引模型根据 Issue 内容生成。
描述
When I build a class with methods that can be chained (they return self), I find that the "commands" help message is written out even when I provide commands with proper arguments and the commands are executed. Here is the code
from __future__ import annotations
from fire import Fire
class Foo:
def act(self, x: int) -> Foo:
"""
Act for some number of minutes.
Parameters
----------
x : int
The number of minutes to act.
"""
print("act", x, "minute(s)")
return self
def rest(self, x: int, y: str = "hours") -> Foo:
"""
Rest for a while.
Parameters
----------
x : int
The time to rest.
y : str
The units of x. The default is hours.
"""
print("rest", x, y)
return self
if __name__ == "__main__":
Fire(Foo)
If I run this as python fire_bug.py, I get the help output I expect, which is
NAME
fire_bug.py act 1
SYNOPSIS
fire_bug.py act 1 COMMAND
COMMANDS
COMMAND is one of the following:
act
Act for some number of minutes.
rest
Rest for a while.
If I run this as python fire_bug.py act 1, I unexpectedly get the help output
NAME
fire_bug.py act 1
SYNOPSIS
fire_bug.py act 1 COMMAND
COMMANDS
COMMAND is one of the following:
act
Act for some number of minutes.
rest
Rest for a while.
followed by the output I expect, which is
act 1 minute(s)
If run this as python fire_bug.py act 1 rest 9, I again unexpectedly get the help output
NAME
fire_bug.py act 1 rest 9
SYNOPSIS
fire_bug.py act 1 rest 9 - COMMAND
COMMANDS
COMMAND is one of the following:
act
Act for some number of minutes.
rest
Rest for a while.
followed by the output I expect, which is
act 1 minute(s)
rest 9 hours
If I add a __str__ method to the class that returns "\b", I don't get the unexpected messages, but I also don't get a help message if I run python fire_bug.py.
As a general observation, running python fire_bug.py --help does not produce useful output. The output is
NAME
fire_bug.py
SYNOPSIS
fire_bug.py -
The output I would expect would be the output I get when I run python fire_bug.py. I am aware that if I have an __init__ method with arguments that the information about those arguments will be displayed, but separating the two sets of information in this way is quite counterintuitive. Both sets of information should be provided when running with no command and when running with only a --help argument.
- 主要语言
- Python
- 星标
- 28.2k
- 派生
- 1.5k
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
google/python-fire 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
google/python-fire#693 ·
-
Release 0.7.2? 未关闭
难度 3/5 1-2 天 新手友好度 38/100
google/python-fire#698 ·
-
难度 3/5 1-2 天 新手友好度 58/100
google/python-fire#672 · 5 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
google/python-fire#665 · 2 条评论 ·
-
难度 4/5 3-5 天 新手友好度 55/100
google/python-fire#659 · 1 条评论 ·
查看 google/python-fire 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 90/100
learningequality/ricecooker#747 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 76/100
run-llama/llama_index#23199 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
KhronosGroup/glTF-Blender-IO#2769 ·