every function now has attribute '.help()', which will print help on call
authorAlexander Solovyov <alexander@solovyov.net>
Sun, 23 Jan 2011 18:12:33 +0100
changeset 161 876a22f3d154
parent 160 82b562890ed7
child 162 e924a731e195
every function now has attribute '.help()', which will print help on call
opster.py
tests/opster.t
--- 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
 
--- 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!