]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/scripts/debug.py
cli: improve formatting of all commands
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / scripts / debug.py
index fedd69851e312c28ca6b871d74fce84a4a39c198..738f911e39307b60a35b6ae07b92bfe307de5c79 100644 (file)
@@ -11,25 +11,21 @@ from allmydata.scripts.common import BaseOptions
 
 class DumpOptions(BaseOptions):
     def getSynopsis(self):
-        return "Usage: tahoe [global-opts] debug dump-share SHARE_FILENAME"
+        return "Usage: tahoe [global-options] debug dump-share SHARE_FILENAME"
 
     optFlags = [
         ["offsets", None, "Display a table of section offsets."],
         ["leases-only", None, "Dump leases but not CHK contents."],
         ]
 
-    def getUsage(self, width=None):
-        t = BaseOptions.getUsage(self, width)
-        t += """
+    description = """
 Print lots of information about the given share, by parsing the share's
 contents. This includes share type, lease information, encoding parameters,
 hash-tree roots, public keys, and segment sizes. This command also emits a
 verify-cap for the file that uses the share.
 
  tahoe debug dump-share testgrid/node-3/storage/shares/4v/4vozh77tsrw7mdhnj7qvp5ky74/0
-
 """
-        return t
 
     def parseArgs(self, filename):
         from allmydata.util.encodingutil import argv_to_abspath
@@ -408,7 +404,7 @@ def dump_MDMF_share(m, length, options):
 
 class DumpCapOptions(BaseOptions):
     def getSynopsis(self):
-        return "Usage: tahoe [global-opts] debug dump-cap [options] FILECAP"
+        return "Usage: tahoe [global-options] debug dump-cap [options] FILECAP"
     optParameters = [
         ["nodeid", "n",
          None, "Specify the storage server nodeid (ASCII), to construct WE and secrets."],
@@ -420,9 +416,7 @@ class DumpCapOptions(BaseOptions):
     def parseArgs(self, cap):
         self.cap = cap
 
-    def getUsage(self, width=None):
-        t = BaseOptions.getUsage(self, width)
-        t += """
+    description = """
 Print information about the given cap-string (aka: URI, file-cap, dir-cap,
 read-cap, write-cap). The URI string is parsed and unpacked. This prints the
 type of the cap, its storage index, and any derived keys.
@@ -437,7 +431,6 @@ If additional information is provided (storage server nodeid and/or client
 base secret), this command will compute the shared secrets used for the
 write-enabler and for lease-renewal.
 """
-        return t
 
 
 def dump_cap(options):
@@ -610,16 +603,14 @@ def dump_uri_instance(u, nodeid, secret, out, show_header=True):
 
 class FindSharesOptions(BaseOptions):
     def getSynopsis(self):
-        return "Usage: tahoe [global-opts] debug find-shares STORAGE_INDEX NODEDIRS.."
+        return "Usage: tahoe [global-options] debug find-shares STORAGE_INDEX NODEDIRS.."
 
     def parseArgs(self, storage_index_s, *nodedirs):
         from allmydata.util.encodingutil import argv_to_abspath
         self.si_s = storage_index_s
         self.nodedirs = map(argv_to_abspath, nodedirs)
 
-    def getUsage(self, width=None):
-        t = BaseOptions.getUsage(self, width)
-        t += """
+    description = """
 Locate all shares for the given storage index. This command looks through one
 or more node directories to find the shares. It returns a list of filenames,
 one per line, for each share file found.
@@ -630,7 +621,6 @@ It may be useful during testing, when running a test grid in which all the
 nodes are on a local disk. The share files thus located can be counted,
 examined (with dump-share), or corrupted/deleted to test checker/repairer.
 """
-        return t
 
 def find_shares(options):
     """Given a storage index and a list of node directories, emit a list of
@@ -659,9 +649,6 @@ def find_shares(options):
 
 
 class CatalogSharesOptions(BaseOptions):
-    """
-
-    """
     def parseArgs(self, *nodedirs):
         from allmydata.util.encodingutil import argv_to_abspath
         self.nodedirs = map(argv_to_abspath, nodedirs)
@@ -669,11 +656,9 @@ class CatalogSharesOptions(BaseOptions):
             raise usage.UsageError("must specify at least one node directory")
 
     def getSynopsis(self):
-        return "Usage: tahoe [global-opts] debug catalog-shares NODEDIRS.."
+        return "Usage: tahoe [global-options] debug catalog-shares NODEDIRS.."
 
-    def getUsage(self, width=None):
-        t = BaseOptions.getUsage(self, width)
-        t += """
+    description = """
 Locate all shares in the given node directories, and emit a one-line summary
 of each share. Run it like this:
 
@@ -691,7 +676,6 @@ you see shares with the same SI but different parameters/filesize/UEB_hash,
 then something is wrong. The misc/find-share/anomalies.py script may be
 useful for purpose.
 """
-        return t
 
 def call(c, *args, **kwargs):
     # take advantage of the fact that ImmediateReadBucketProxy returns
@@ -882,15 +866,13 @@ def catalog_shares_one_abbrevdir(si_s, si_dir, now, out, err):
 
 class CorruptShareOptions(BaseOptions):
     def getSynopsis(self):
-        return "Usage: tahoe [global-opts] debug corrupt-share SHARE_FILENAME"
+        return "Usage: tahoe [global-options] debug corrupt-share SHARE_FILENAME"
 
     optParameters = [
         ["offset", "o", "block-random", "Specify which bit to flip."],
         ]
 
-    def getUsage(self, width=None):
-        t = BaseOptions.getUsage(self, width)
-        t += """
+    description = """
 Corrupt the given share by flipping a bit. This will cause a
 verifying/downloading client to log an integrity-check failure incident, and
 downloads will proceed with a different share.
@@ -902,7 +884,6 @@ to flip a single random bit of the block data.
 
 Obviously, this command should not be used in normal operation.
 """
-        return t
     def parseArgs(self, filename):
         self['filename'] = filename
 
@@ -962,7 +943,7 @@ def corrupt_share(options):
 
 class ReplOptions(BaseOptions):
     def getSynopsis(self):
-        return "Usage: tahoe [global-opts] debug repl"
+        return "Usage: tahoe [global-options] debug repl"
 
 def repl(options):
     import code
@@ -973,7 +954,7 @@ DEFAULT_TESTSUITE = 'allmydata'
 
 class TrialOptions(twisted_trial.Options):
     def getSynopsis(self):
-        return "Usage: tahoe [global-opts] debug trial [options] [[file|package|module|TestCase|testmethod]...]"
+        return "Usage: tahoe [global-options] debug trial [options] [[file|package|module|TestCase|testmethod]...]"
 
     def parseOptions(self, all_subargs, *a, **kw):
         self.trial_args = list(all_subargs)
@@ -985,13 +966,10 @@ class TrialOptions(twisted_trial.Options):
         if not nonoption_args:
             self.trial_args.append(DEFAULT_TESTSUITE)
 
-    def getUsage(self, width=None):
-        t = twisted_trial.Options.getUsage(self, width)
-        t += """
-The 'tahoe debug trial' command uses the correct imports for this instance of
-Tahoe-LAFS. The default test suite is '%s'.
-""" % (DEFAULT_TESTSUITE,)
-        return t
+    longdesc = twisted_trial.Options.longdesc + "\n\n" + (
+        "The 'tahoe debug trial' command uses the correct imports for this "
+        "instance of Tahoe-LAFS. The default test suite is '%s'."
+        % DEFAULT_TESTSUITE)
 
 def trial(config):
     sys.argv = ['trial'] + config.trial_args
@@ -1014,9 +992,9 @@ def fixOptionsClass( (subcmd, shortcut, OptionsClass, desc) ):
             t = OptionsClass.getSynopsis(self)
             i = t.find("Usage: flogtool ")
             if i >= 0:
-                return "Usage: tahoe [global-opts] debug flogtool " + t[i+len("Usage: flogtool "):]
+                return "Usage: tahoe [global-options] debug flogtool " + t[i+len("Usage: flogtool "):]
             else:
-                return "Usage: tahoe [global-opts] debug flogtool %s [options]" % (subcmd,)
+                return "Usage: tahoe [global-options] debug flogtool %s [options]" % (subcmd,)
     return (subcmd, shortcut, FixedOptionsClass, desc)
 
 class FlogtoolOptions(foolscap_cli.Options):
@@ -1025,7 +1003,7 @@ class FlogtoolOptions(foolscap_cli.Options):
         self.subCommands = map(fixOptionsClass, self.subCommands)
 
     def getSynopsis(self):
-        return "Usage: tahoe [global-opts] debug flogtool (%s) [command options]" % ("|".join([x[0] for x in self.subCommands]))
+        return "Usage: tahoe [global-options] debug flogtool COMMAND [flogtool-options]"
 
     def parseOptions(self, all_subargs, *a, **kw):
         self.flogtool_args = list(all_subargs)
@@ -1037,7 +1015,7 @@ class FlogtoolOptions(foolscap_cli.Options):
 The 'tahoe debug flogtool' command uses the correct imports for this instance
 of Tahoe-LAFS.
 
-Please run 'tahoe debug flogtool SUBCOMMAND --help' for more details on each
+Please run 'tahoe debug flogtool COMMAND --help' for more details on each
 subcommand.
 """
         return t
@@ -1066,20 +1044,11 @@ class DebugCommand(BaseOptions):
     def postOptions(self):
         if not hasattr(self, 'subOptions'):
             raise usage.UsageError("must specify a subcommand")
-    def getSynopsis(self):
-        return ""
+    synopsis = "COMMAND"
+
     def getUsage(self, width=None):
-        #t = BaseOptions.getUsage(self, width)
-        t = """Usage: tahoe debug SUBCOMMAND
-Subcommands:
-    tahoe debug dump-share      Unpack and display the contents of a share.
-    tahoe debug dump-cap        Unpack a read-cap or write-cap.
-    tahoe debug find-shares     Locate sharefiles in node directories.
-    tahoe debug catalog-shares  Describe all shares in node dirs.
-    tahoe debug corrupt-share   Corrupt a share by flipping a bit.
-    tahoe debug repl            Open a Python interpreter.
-    tahoe debug trial           Run tests using Twisted Trial with the right imports.
-    tahoe debug flogtool        Utilities to access log files.
+        t = BaseOptions.getUsage(self, width)
+        t += """\
 
 Please run e.g. 'tahoe debug dump-share --help' for more details on each
 subcommand.