def docopt_cmd(func):
def fn(self, arg):
try:
if fn.__name__ == "do_pub":
# Fix for negative numbers
opt = docopt(fn.__doc__, arg, options_first=True)
else:
opt = docopt(fn.__doc__, arg)
except DocoptExit as e:
print('Command is invalid. See :')
print(e)
return
except SystemExit:
# The SystemExit exception prints the usage for --help
# We do not need to do the print here.
return
return func(self, opt)
fn.__name__ = func.__name__
fn.__doc__ = func.__doc__
fn.__dict__.update(func.__dict__)
return fn
评论列表
文章目录