Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behaviour with capitals in function names #17

Closed
mwort opened this issue Dec 14, 2016 · 3 comments
Closed

Unexpected behaviour with capitals in function names #17

mwort opened this issue Dec 14, 2016 · 3 comments
Assignees
Milestone

Comments

@mwort
Copy link

mwort commented Dec 14, 2016

Hi team, I have tried getting my head around using clize and I came across unexpected behaviour with function names that use capitals. For a start, what is the rational for altering the function names, ie. converting all to lower case and replying underscores? To me it defeats the point of having a CLI that corresponds to my code as closely as possible. I'm guessing it's a Windows related problem. But here is the buggy thing about it. Mini example from the docs, with a camel-cased function name:

import clize
def addThis():
    return "OK I will remember that."

def list_():
    """Lists the existing entries."""
    return "Sorry I forgot it all :("

if __name__=='__main__':
    clize.run(addThis, list_)

On the command line:

$> python testclize.py --help
Usage: testclize.py command [args...]

Commands:
  addThis
  list      Lists the existing entries.

Great, addThis is a command. But then:

$> python testclize.py addThis
testclize.py: Unknwon command "addthis"
$> python testclize.py addthis
testclize.py: Unknwon command "addthis"

What am I missing here?
Tested on both py2.7 and 3.5 under Linux SLES 11.3 (64_x86).

@epsy
Copy link
Owner

epsy commented Dec 14, 2016

Hello and thanks for the bug report!

Clize alters function names in an effort to translate Python conventions (snake_case and avoid_builtin_names_) to a set of CLI conventions (e.g. git cherry-pick), as a continuation to translating Python call idioms (f(a1, p=a2)) to CLI ones (f a1 -p a2).

It looks like camel case wasn't considered in the translation. Clize should definitely translate addThis or AddThis to add-this, so I'll look into that.

As a workaround you can use add_this if it doesn't clash with your coding style.

As this may be surprising behavior, I will make sure it is adequately documented in the reference and tutorials.

@epsy epsy added this to the 3.2 milestone Dec 14, 2016
@mwort
Copy link
Author

mwort commented Dec 14, 2016

Thanks epsy, more about the conversion in the doc would be great, I'm actually having difficulties finding the function in the code. I get the CLI conventions point but I still think it's a shame not being able to use exactly the same function names as they appear in the code. An automatic alias to the actual function names would be great, so both options work:

python testclize.py add-this     # correct CLI way as shown in --help
python testclize.py add_This   # but this works too, because this is the actual function name

Just a thought because as a new user, you'd expect this behaviour to work like that. Or a git-style error may be even better:

python testclize.py add_This
testclize.py: Unknwon command "add_This", do you mean "add-this" (name changed due to CLI naming convention)?

@epsy
Copy link
Owner

epsy commented Dec 14, 2016 via email

@epsy epsy self-assigned this Dec 23, 2016
@epsy epsy closed this as completed in bea81ca Dec 23, 2016
epsy added a commit that referenced this issue Dec 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants