BUG: When using a Class for grouping commands `--self` shows as a flag
还没有人认领这个 Issue。
评估
调研方向
从 fire/completion.py 开始,并使用 python3 example.py -- --completion 复现示例。跟踪类方法如何转换为补全选项,然后验证生成的 Bash 补全不再为 bar 或 do-stuff 列出 --self,同时保留 --arg1。
由索引模型根据 Issue 内容生成。
描述
Example code (example.py):
import fire
class Foo:
def bar(self):
return 'bar'
def do_stuff(self, arg1):
return 'stuff'
if __name__ == '__main__':
fire.Fire(Foo)
Run:
python3 example.py -- --completion
Completion Output (take note of --self in output):
# bash completion support for example.py
# DO NOT EDIT.
# This script is autogenerated by fire/completion.py.
_complete-examplepy()
{
local cur prev opts lastcommand
COMPREPLY=()
prev="${COMP_WORDS[COMP_CWORD-1]}"
cur="${COMP_WORDS[COMP_CWORD]}"
lastcommand=$(get_lastcommand)
opts=""
GLOBAL_OPTIONS=""
case "${lastcommand}" in
bar)
if is_prev_global; then
opts="${GLOBAL_OPTIONS}"
else
opts="--self ${GLOBAL_OPTIONS}"
fi
opts=$(filter_options $opts)
;;
do-stuff)
if is_prev_global; then
opts="${GLOBAL_OPTIONS}"
else
opts="--arg1 --self ${GLOBAL_OPTIONS}"
fi
opts=$(filter_options $opts)
;;
example.py)
opts="bar do-stuff ${GLOBAL_OPTIONS}"
opts=$(filter_options $opts)
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
get_lastcommand()
{
local lastcommand i
lastcommand=
for ((i=0; i < ${#COMP_WORDS[@]}; ++i)); do
if [[ ${COMP_WORDS[i]} != -* ]] && [[ -n ${COMP_WORDS[i]} ]] && [[
${COMP_WORDS[i]} != $cur ]]; then
lastcommand=${COMP_WORDS[i]}
fi
done
echo $lastcommand
}
filter_options()
{
local opts
opts=""
for opt in "$@"
do
if ! option_already_entered $opt; then
opts="$opts $opt"
fi
done
echo $opts
}
option_already_entered()
{
local opt
for opt in ${COMP_WORDS[@]:0:COMP_CWORD}
do
if [ $1 == $opt ]; then
return 0
fi
done
return 1
}
is_prev_global()
{
local opt
for opt in $GLOBAL_OPTIONS
do
if [ $opt == $prev ]; then
return 0
fi
done
return 1
}
complete -F _complete-examplepy example.py
- 主要语言
- 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
-
难度 2/5 1-3 小时 新手友好度 78/100
syfoud/Simulated_Scepter#172 ·
-
A cancelled tests run makes the coverage comment workflow fail and reports it as a red check on main 未关闭area: ci bug perceived difficulty: 3
难度 2/5 1-3 小时 新手友好度 78/100
Nitjsefnie-Harness-Commons/daedalus#921 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 86/100
EleutherAI/lm-evaluation-harness#4207 ·
-
难度 1/5 1 小时以内 新手友好度 92/100
-
难度 2/5 1-3 小时 新手友好度 78/100
ClickHouse/clickhouse-connect#1057 ·