# HG changeset patch # User Alexander Solovyov <alexander@solovyov.net> # Date 1295802753 -3600 # Node ID 876a22f3d1548e2ab9912de819b3c8c084c1b6d2 # Parent 82b562890ed7ca1382010e4194e56ade9a9ddd12 every function now has attribute '.help()', which will print help on call diff -r 82b562890ed7 -r 876a22f3d154 opster.py --- a/opster.py Sun Jan 23 18:02:33 2011 +0100 +++ b/opster.py Sun Jan 23 18:12:33 2011 +0100 @@ -70,6 +70,7 @@ def help_func(name=None): return help_cmd(func, replace_name(usage_, sysname()), options_) + func.help = help_func @wraps(func) def inner(*args, **opts): @@ -82,23 +83,23 @@ argv = opts.pop('argv', sys.argv[1:]) if opts.pop('help', False): - return help_func() + return func.help() if args or opts: # no catcher here because this is call from Python return call_cmd_regular(func, options_)(*args, **opts) try: - opts, args = catcher(lambda: parse(argv, options_), help_func) + opts, args = catcher(lambda: parse(argv, options_), func.help) except Abort: return -1 if opts.pop('help', False): - return help_func() + return func.help() try: return catcher(lambda: call_cmd(name_, func)(*args, **opts), - help_func) + func.help) except Abort: return -1 diff -r 82b562890ed7 -r 876a22f3d154 tests/opster.t --- a/tests/opster.t Sun Jan 23 18:02:33 2011 +0100 +++ b/tests/opster.t Sun Jan 23 18:12:33 2011 +0100 @@ -156,4 +156,17 @@ -h --help show help +Another things should be checked: calling help display from the function +itself:: + + $ run selfhelp.py --assist + selfhelp.py [OPTIONS] + + Displays ability to show help + + options: + + --assist show help + -h --help show help + That's all for today; see you next time!