docopt-dispatch
docopt-dispatch copied to clipboard
Dispatch on best match
Hello, I use docopt and this lib a lot, but I have problems with dispatching mechanism by order. I am forced to reorder my functions every time because I have commands like these:
"""
Usage:
cli
cli parse <url>
cli parse all
"""
@dispatch.on()
def foo(**kwargs):
pass
@dispatch.on("parse")
def foo(**kwargs):
pass
@dispatch.on("parse", "all")
def foo(**kwargs):
pass
I know I can reorder them to be working, but it's kind of trap. Because I always forget about this "feature" and I am debugging why my code is doing something else. And it's not easy task to find the reason :(
IMHO better approach would be to match on best match - function that matches the greatest number of arguments. This way everybody can order functions the way he likes :) What do you think?