Commits

Doug Hellmann  committed 91bd795

print the list of core hooks if no hook name is given in list mode

  • Participants
  • Parent commits 59d8999

Comments (0)

Files changed (3)

File docs/en/history.rst

   - Fix the test script and runner so the user's ``$WORKON_HOME`` is
     not erased if they do not have some test shells installed.
     (big thanks to :bbuser:`agriffis`).
+  - If the hook loader is told to list plugins but is not given a hook
+    name, it prints the list of core hooks.
 
 3.2
 

File virtualenvwrapper.sh

 
     cd "$PROJECT_HOME"
 
-    virtualenvwrapper_run_hook project.pre_mkproject $envname
+    virtualenvwrapper_run_hook "project.pre_mkproject" $envname
 
     echo "Creating $PROJECT_HOME/$envname"
     mkdir -p "$PROJECT_HOME/$envname"
         # For some reason zsh insists on prefixing the template
         # names with a space, so strip them out before passing
         # the value to the hook loader.
-        virtualenvwrapper_run_hook --name $(echo $t | sed 's/^ //') project.template $envname
+        virtualenvwrapper_run_hook --name $(echo $t | sed 's/^ //') "project.template" $envname
     done
 
-    virtualenvwrapper_run_hook project.post_mkproject
+    virtualenvwrapper_run_hook "project.post_mkproject"
 }
 
 # Change directory to the active project

File virtualenvwrapper/hook_loader.py

 """
 
 import inspect
+import itertools
 import logging
 import logging.handlers
 import optparse
 
     # Determine which hook we're running
     if not args:
-        parser.error('Please specify the hook to run')
+        if options.listing:
+            list_hooks()
+            return 0
+        else:
+            parser.error('Please specify the hook to run')
     hook = args[0]
 
     if options.sourcing and options.script_filename:
 
     return 0
 
+
 def run_hooks(hook, options, args, output=None):
     if output is None:
         output = sys.stdout
             continue
         plugin = ep.load()
         if options.listing:
-            sys.stdout.write('  %-10s -- %s\n' % (ep.name, inspect.getdoc(plugin) or ''))
+            output.write('  %-10s -- %s\n' % (ep.name, inspect.getdoc(plugin) or ''))
             continue
         if options.sourcing:
             # Show the shell commands so they can
             # Just run the plugin ourselves
             plugin(args[1:])
 
+
+def list_hooks(output=None):
+    if output is None:
+        output = sys.stdout
+    for hook in itertools.chain(
+        ('_'.join(h)
+         for h in itertools.product(['pre', 'post'],
+                                    ['mkvirtualenv',
+                                     'rmvirtualenv',
+                                     'activate',
+                                     'deactivate',
+                                     'cpvirtualenv',
+                                     ])
+         ),
+        ['initialize',
+         'get_env_details',
+         'project.pre_mkproject',
+         'project.post_mkproject',
+         'project.template',
+         ]
+        ):
+        output.write(hook + '\n')
+
+
 if __name__ == '__main__':
     main()