]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
startstop_node.py: improve error reporting and help.
authorDavid-Sarah Hopwood <david-sarah@jacaranda.org>
Thu, 3 Jan 2013 18:53:39 +0000 (18:53 +0000)
committerDaira Hopwood <daira@jacaranda.org>
Tue, 14 Oct 2014 17:12:20 +0000 (18:12 +0100)
src/allmydata/scripts/startstop_node.py

index 90ec10464ea3817f56d3bc9fb0f5a3cddd62f7d2..a0c69bb602aa9589169952c1e9c20a29d14cc776 100644 (file)
@@ -7,7 +7,12 @@ from allmydata.util import fileutil
 from allmydata.util.encodingutil import listdir_unicode, quote_output
 
 
+def format_twisted_options(config):
+    return "twistd %s\n" % (str(config).partition("\n")[2].partition("\n\n")[0],)
+
 class StartOptions(BasedirOptions):
+    subcommand_name = "start"
+
     def parseArgs(self, basedir=None, *twistd_args):
         # this can't handle e.g. 'tahoe start --nodaemon', since then
         # --nodaemon looks like a basedir. So you can either use 'tahoe
@@ -19,22 +24,22 @@ class StartOptions(BasedirOptions):
         self.twistd_args = twistd_args
 
     def getSynopsis(self):
-        return "Usage:  %s [global-opts] start [options] [NODEDIR]" % (self.command_name,)
+        return "Usage:  %s [global-opts] %s [options] [NODEDIR] [twistd_options]" % (self.command_name, self.subcommand_name)
 
+    def getUsage(self, width=None):
+        t = BaseOptions.getUsage(self, width) + "\n"
+        t += format_twisted_options(MyTwistdConfig())
+        return t
 
 class StopOptions(BasedirOptions):
     def getSynopsis(self):
         return "Usage:  %s [global-opts] stop [options] [NODEDIR]" % (self.command_name,)
 
-
 class RestartOptions(StartOptions):
-    def getSynopsis(self):
-        return "Usage:  %s [global-opts] restart [options] [NODEDIR]" % (self.command_name,)
-
+    subcommand_name = "restart"
 
 class RunOptions(StartOptions):
-    def getSynopsis(self):
-        return "Usage:  %s [global-opts] run [options] [NODEDIR]" % (self.command_name,)
+    subcommand_name = "run"
 
 
 class MyTwistdConfig(twistd.ServerOptions):
@@ -111,8 +116,9 @@ def start(config, out=sys.stdout, err=sys.stderr):
         twistd_config.parseOptions(twistd_args)
     except usage.error, ue:
         # these arguments were unsuitable for 'twistd'
-        print >>err, twistd_config
-        print >>err, "tahoe start: %s" % (config.subCommand, ue)
+        print >>err, config
+        print >>err, format_twisted_options(twistd_config)
+        print >>err, "tahoe %s: %s\n" % (config.subcommand_name, ue)
         return 1
     twistd_config.loadedPlugins = {"StartTahoeNode": StartTahoeNodePlugin(nodetype, basedir)}