google / google/python-fire

Version flag alongside other commands

未關閉
#468 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
28.2k
分支
1.5k
PR 合併指標
30 天內沒有已合併 PR

描述

I have a script which has multiple commands, each of which have their own arguments etc. I would like to add a simple flag to be used standalone to simply display the version of my script. I would like the the `--help` display to additionally show users this flag is available without affecting the other commands. For instance if my script is called `foo`, I'd like to be able to do:

`foo --version` or `foo -v`

but I'd still like to do:

`foo mycommand myarg` etc.

The two closest solutions I've tried each have a downside:

- the flags and the commands are displayed in different help windows e.g. `foo --help` shows the help window for the flags whilst `foo` standlone shows the help window for the commands
- the help window shows both flags and commands but the flag is interpreted as a flag _to the commands_ such that if I type `foo --version`, the version is displayed but so is the help window because it thinks a command is missing

I'm using `fire==0.5.0`. Is there any way I can achieve this?

貢獻指南

開啟貢獻指南

研究方向

Start by reproducing the reported behavior with Python Fire 0.5.0 using a callable that exposes multiple commands, then trace how standalone flags and command help are assembled. Compare `foo --version`, `foo -v`, `foo --help`, and `foo mycommand myarg`; done means the version flags work independently, appear in the relevant help output, and do not alter existing command behavior.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
cli
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。