web/lib/django/core/management/commands/dbshell.py
changeset 29 cc9b7e14412b
parent 0 0d40e90630ef
--- a/web/lib/django/core/management/commands/dbshell.py	Wed May 19 17:43:59 2010 +0200
+++ b/web/lib/django/core/management/commands/dbshell.py	Tue May 25 02:43:45 2010 +0200
@@ -1,12 +1,22 @@
-from django.core.management.base import NoArgsCommand, CommandError
+from optparse import make_option
+
+from django.core.management.base import BaseCommand, CommandError
+from django.db import connections, DEFAULT_DB_ALIAS
 
-class Command(NoArgsCommand):
-    help = "Runs the command-line client for the current DATABASE_ENGINE."
+class Command(BaseCommand):
+    help = ("Runs the command-line client for specified database, or the "
+        "default database if none is provided.")
+
+    option_list = BaseCommand.option_list + (
+        make_option('--database', action='store', dest='database',
+            default=DEFAULT_DB_ALIAS, help='Nominates a database onto which to '
+                'open a shell.  Defaults to the "default" database.'),
+    )
 
     requires_model_validation = False
 
-    def handle_noargs(self, **options):
-        from django.db import connection
+    def handle(self, **options):
+        connection = connections[options.get('database', DEFAULT_DB_ALIAS)]
         try:
             connection.client.runshell()
         except OSError: