Open jgat opened 10 years ago
The following is a workaround (but maybe not a nice one):
#!/usr/bin/env python
import begin
@begin.subcommand(name='a')
def z():
print "z"
z.__name__ = 'a'
@begin.subcommand(name='b')
def y():
print "y"
y.__name__ = 'b'
@begin.start
def run():
pass
Note that both the name=???
and __name__ = ???
must be the same.
When subcommands are created with custom names, the application doesn't respect those names. I've deduced that what's actually happening is the custom name is being registered, but when the subcommand is actually registered in argparse, it uses name (possibly in other places as well, I've only had a cursory look through the source).
An example will demonstrate:
Then, running as
eg.py
,Note that the commands are being sorted by the custom name (as shown here).
A hacky workaround is to just modify
func.__name__
attribute insubcommands.Collector.register
; this would only cause problems if the function (and in particular, the function's__name__
) was going to be used for something else in addition to being a subcommand. (Which to be honest, is most likely an obscure scenario.)And then there's also this, which I suspect is an entirely separate issue, probably related to #44; this error does not occur when the custom name is removed:
Edit: I now believe this is very much related: because the rest of the system is using the function's name instead of the name it's registered with, calls to
.get
will returnNone
, and then thatNone
gets passed tosignature
, which causes theTypeError
.