--- old-tahoe/src/allmydata/scripts/common.py	2010-01-12 04:29:38.233000000 +0000
+++ new-tahoe/src/allmydata/scripts/common.py	2010-01-12 04:29:38.299000000 +0000
@@ -1,6 +1,21 @@
 
 import os, sys, urllib
 from twisted.python import usage
+from allmydata.util.assertutil import precondition
+
+
+_default_basedir = None
+if sys.platform == 'win32':
+    from allmydata.windows import registry
+    path = registry.get_base_dir_path()
+    if path:
+        precondition(isinstance(path, (str, unicode)), path)
+        _default_basedir = os.path.abspath(path)
+
+if _default_basedir is None:
+    path = os.path.expanduser("~/.tahoe")
+    precondition(isinstance(path, (str, unicode)), path)
+    _default_basedir = os.path.abspath(path)
 
 
 class BaseOptions:
@@ -15,6 +30,11 @@
         ["version-and-path", None, "Display version numbers and paths to their locations and exit."],
         ]
 
+    optParameters = [
+        ["basedir", "C", None, "Specify the base directory of the node to be used." + (
+            "" if _default_basedir is None else " [default for most commands: " + _default_basedir + "]")],
+    ]
+    
     def opt_version(self):
         import allmydata
         print allmydata.get_package_versions_string()
@@ -27,19 +47,20 @@
 
 
 class BasedirMixin:
+    use_default_basedir = True
+
     optFlags = [
-        ["multiple", "m", "allow multiple basedirs to be specified at once"],
+        ["multiple", "m", "Specify multiple base directories at once."],
         ]
 
     def postOptions(self):
         if not self.basedirs:
-            raise usage.UsageError("<basedir> parameter is required")
+            raise usage.UsageError("A base directory must be provided using --basedir or --multiple.")
         if self['basedir']:
             del self['basedir']
         self['basedirs'] = [os.path.abspath(os.path.expanduser(b)) for b in self.basedirs]
 
     def parseArgs(self, *args):
-        from allmydata.util.assertutil import precondition
         self.basedirs = []
         if self['basedir']:
             precondition(isinstance(self['basedir'], (str, unicode)), self['basedir'])
@@ -48,41 +69,18 @@
             precondition(not [x for x in args if not isinstance(x, (str, unicode))], args)
             self.basedirs.extend(args)
         else:
-            if len(args) == 0 and not self.basedirs:
-                if sys.platform == 'win32':
-                    from allmydata.windows import registry
-                    rbdp = registry.get_base_dir_path()
-                    if rbdp:
-                        precondition(isinstance(registry.get_base_dir_path(), (str, unicode)), registry.get_base_dir_path())
-                        self.basedirs.append(rbdp)
-                else:
-                    precondition(isinstance(os.path.expanduser("~/.tahoe"), (str, unicode)), os.path.expanduser("~/.tahoe"))
-                    self.basedirs.append(os.path.expanduser("~/.tahoe"))
+            if self.use_default_basedir and len(args) == 0 and not self.basedirs:
+                self.basedirs.append(_default_basedir)
             if len(args) > 0:
                 precondition(isinstance(args[0], (str, unicode)), args[0])
                 self.basedirs.append(args[0])
             if len(args) > 1:
                 raise usage.UsageError("I wasn't expecting so many arguments")
 
+
 class NoDefaultBasedirMixin(BasedirMixin):
-    def parseArgs(self, *args):
-        from allmydata.util.assertutil import precondition
-        # create-client won't default to --basedir=~/.tahoe
-        self.basedirs = []
-        if self['basedir']:
-            precondition(isinstance(self['basedir'], (str, unicode)), self['basedir'])
-            self.basedirs.append(self['basedir'])
-        if self['multiple']:
-            precondition(not [x for x in args if not isinstance(x, (str, unicode))], args)
-            self.basedirs.extend(args)
-        else:
-            if len(args) > 0:
-                precondition(isinstance(args[0], (str, unicode)), args[0])
-                self.basedirs.append(args[0])
-            if len(args) > 1:
-                raise usage.UsageError("I wasn't expecting so many arguments")
-        if not self.basedirs:
-            raise usage.UsageError("--basedir must be provided")
+    use_default_basedir = False
+
 
 DEFAULT_ALIAS = "tahoe"
 
@@ -96,7 +94,7 @@
         f = open(rootfile, "r")
         rootcap = f.read().strip()
         if rootcap:
-            aliases["tahoe"] = uri.from_string_dirnode(rootcap).to_string()
+            aliases[DEFAULT_ALIAS] = uri.from_string_dirnode(rootcap).to_string()
     except EnvironmentError:
         pass
     try:
