Fix help for options with functions as their default arguments
authorAlexander Solovyov <piranha@piranha.org.ua>
Thu, 11 Feb 2010 18:48:44 +0200
changeset 101 7507884b8dff
parent 100 78a1e77609e6
child 102 dc0b74705b3d
Fix help for options with functions as their default arguments
opster.py
tests/test_opts.out
tests/test_opts.py
--- a/opster.py	Wed Feb 10 10:31:27 2010 +0200
+++ b/opster.py	Thu Feb 11 18:48:44 2010 +0200
@@ -232,6 +232,8 @@
     yield 'options:\n\n'
     output = []
     for short, name, default, desc in options:
+        if hasattr(default, '__call__'):
+            default = default(None)
         default = default and ' (default: %s)' % default or ''
         output.append(('%2s%s' % (short and '-%s' % short,
                                   name and ' --%s' % name),
--- a/tests/test_opts.out	Wed Feb 10 10:31:27 2010 +0200
+++ b/tests/test_opts.out	Thu Feb 11 18:48:44 2010 +0200
@@ -10,6 +10,7 @@
  -p --port       port to listen on (default: 8000)
  -d --daemonize  daemonize process
     --pid-file   name of file to write process ID to
+ -t --test       testing help for a function (default: test)
  -h --help       show help
 test_opts.py [-l HOST] DIR
 
@@ -23,5 +24,6 @@
  -p --port       port to listen on (default: 8000)
  -d --daemonize  daemonize process
     --pid-file   name of file to write process ID to
+ -t --test       testing help for a function (default: test)
  -h --help       show help
-{'pid_file': '', 'daemonize': False, 'dirname': '.', 'port': 8000, 'listen': 'localhost'}
+{'pid_file': '', 'daemonize': False, 'test': 'test', 'dirname': '.', 'port': 8000, 'listen': 'localhost'}
--- a/tests/test_opts.py	Wed Feb 10 10:31:27 2010 +0200
+++ b/tests/test_opts.py	Thu Feb 11 18:48:44 2010 +0200
@@ -22,7 +22,8 @@
             listen=('l', 'localhost', 'ip to listen on'),
             port=('p', 8000, 'port to listen on'),
             daemonize=('d', False, 'daemonize process'),
-            pid_file=('', '', 'name of file to write process ID to')):
+            pid_file=('', '', 'name of file to write process ID to'),
+            test=('t', lambda x: x or 'test', 'testing help for a function')):
     '''Command with option declaration as keyword arguments
 
     Otherwise it's the same as previous command