You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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)?
Both are good options. As a consistency with the existing typo handling for
named options, I'm leaning towards the latter.
IIRC, this is all handled by the private util.name_py2cli function
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:
On the command line:
Great,
addThis
is a command. But then:What am I missing here?
Tested on both py2.7 and 3.5 under Linux SLES 11.3 (64_x86).
The text was updated successfully, but these errors were encountered: