Commits

Doug Hellmann committed 6f6b11c

add -n and -l options to hook loader

Comments (0)

Files changed (2)

docs/source/history.rst

   - Fix a problem with ``virtualenvwrapper_show_workon_options`` that
     caused it to show ``*`` as the name of a virtualenv when no
     environments had yet been created.
+  - Change the hook loader so it can be told to run only a set of
+    named hooks.
+  - Add support for listing the available hooks, to be used in help
+    output of commands like virtualenvwrapper.project's mkproject.
 
 2.0.2
 

virtualenvwrapper/hook_loader.py

 """Load hooks for virtualenvwrapper.
 """
 
+import inspect
 import logging
 import optparse
 import os
                       dest='sourcing',
                       default=False,
                       )
+    parser.add_option('-l', '--list',
+                      help='Print a list of the plugins available for the given hook',
+                      action='store_true',
+                      default=False,
+                      dest='listing',
+                      )
     parser.add_option('-v', '--verbose',
                       help='Show more information on the console',
                       action='store_const',
                       const=0,
                       dest='verbose_level',
                       )
+    parser.add_option('-n', '--name',
+                      help='Only run the hook from the named plugin',
+                      action='append',
+                      dest='names',
+                      default=[],
+                      )
     parser.disable_interspersed_args() # stop when we hit an option without an '-'
     options, args = parser.parse_args()
 
         hook += '_source'
 
     for ep in pkg_resources.iter_entry_points('virtualenvwrapper.%s' % hook):
+        if options.names and ep.name not in options.names:
+            continue
         plugin = ep.load()
+        if options.listing:
+            print '  {0:10} -- {1}'.format(ep.name, inspect.getdoc(plugin) or '')
+            continue
         if options.sourcing:
             # Show the shell commands so they can
             # be run in the calling shell.