google / google/python-fire

Support case-insensitive usage of Python Fire CLIs

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

描述

Much like how we allow users to use hyphens `-` in place of underscores, this Issue is to allow users to use all-lowercase versions of identifiers.

**Typical case**
```
import fire
class CaseExample(object):
def Alpha():
return 'path 1'
fire.Fire(CaseExample)
```

```
$ python example.py Alpha # This is the current behavior.
path 1
$ python example.py alpha # This is the new behavior I want to add.
path 1
$ python example.py ALPHA # Do we want to support other capitalizations? Or just the all lower-case version?
path 1
```

**Corner cases**
Unlike with the -/_ support, there can potentially be members with multiple capitalization variants of the name.

E.g.
```
import fire
class CaseExample(object):
def alpha():
return 'path 1'
def Alpha():
return 'path 2'

fire.Fire(CaseExample)
```

If the user provides an exact match, it's clear what we should do. I'm open to discussion about how to handle the ambiguous case.

```
$ python example.py alpha
path 1
$ python example.py Alpha
path 2
$ python example.py ALPHA
WARNING: Ambiguous member access `ALPHA`; accessing `alpha`.
path 1
```

**Why?**
The primary motivation is that command line tools typically use lower case commands, whereas Python classes (and occasionally methods/functions) typically have capital names. By allowing these capital names to be used via their lower-case variant, the CLIs that result from normal python code will feel natural more often.

**Possible extension**
If we also support dropping/adding -/_s in some situations, then people could use snake-case to refer to CamelCase items... just brainstorming. Thoughts?

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

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

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