From 7fb695f956faaede9dbbb38cb149c3e01556392f Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Mon, 25 Feb 2019 13:34:02 -0500 Subject: [PATCH] Add user-facing help about destinations --- src/allmydata/scripts/runner.py | 2 ++ src/allmydata/test/test_runner.py | 19 +++++++++++++++++++ src/allmydata/util/eliotutil.py | 24 +++++++++++++++++++----- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/allmydata/scripts/runner.py b/src/allmydata/scripts/runner.py index 820e88bc6..9b71ee708 100644 --- a/src/allmydata/scripts/runner.py +++ b/src/allmydata/scripts/runner.py @@ -12,6 +12,7 @@ from allmydata.scripts import debug, create_node, cli, \ from allmydata.util.encodingutil import quote_output, quote_local_unicode_path, get_io_encoding from allmydata.util.eliotutil import ( opt_eliot_destination, + opt_help_eliot_destinations, ) def GROUP(s): @@ -93,6 +94,7 @@ class Options(usage.Options): self.no_command_needed = True opt_eliot_destination = opt_eliot_destination + opt_help_eliot_destinations = opt_help_eliot_destinations def __str__(self): return ("\nUsage: tahoe [global-options] [command-options]\n" diff --git a/src/allmydata/test/test_runner.py b/src/allmydata/test/test_runner.py index 731be35a0..c47670ca7 100644 --- a/src/allmydata/test/test_runner.py +++ b/src/allmydata/test/test_runner.py @@ -168,6 +168,25 @@ class BinTahoe(common_util.SignalMixin, unittest.TestCase, RunBinTahoeMixin): d.addCallback(_cb) return d + @inlineCallbacks + def test_help_eliot_destinations(self): + out, err, rc_or_sig = yield self.run_bintahoe(["--help-eliot-destinations"]) + self.assertIn("\tfile:", out) + self.assertEqual(rc_or_sig, 0) + + @inlineCallbacks + def test_eliot_destination(self): + out, err, rc_or_sig = yield self.run_bintahoe([ + # Proves little but maybe more than nothing. + "--eliot-destination=file:-", + # Throw in *some* command or the process exits with error, making + # it difficult for us to see if the previous arg was accepted or + # not. + "--help", + ]) + self.assertEqual(rc_or_sig, 0) + + class CreateNode(unittest.TestCase): # exercise "tahoe create-node", create-introducer, diff --git a/src/allmydata/util/eliotutil.py b/src/allmydata/util/eliotutil.py index 22872e952..29992944c 100644 --- a/src/allmydata/util/eliotutil.py +++ b/src/allmydata/util/eliotutil.py @@ -15,6 +15,7 @@ __all__ = [ "inline_callbacks", "eliot_logging_service", "opt_eliot_destination", + "opt_help_eliot_destinations", ] from sys import ( @@ -190,11 +191,8 @@ def eliot_logging_service(reactor, destinations): Parse the given Eliot destination descriptions and return an ``IService`` which will add them when started and remove them when stopped. - The following destinations are supported: - - * ``file:[:rotated_length=][:max_rotated_files=]`` - Sensible defaults are supplied for rotated_length and max_rotated_files - if they are not given. + See ``--help-eliot-destinations`` for details about supported + destinations. """ return _EliotLogging(destinations=list( get_destination(reactor) @@ -214,6 +212,22 @@ def opt_eliot_destination(self, description): ) +def opt_help_eliot_destinations(self): + """ + Emit usage information for --eliot-destination. + """ + print( + "Available destinations:\n" + # Might want to generate this from some metadata someday but we just + # have one hard-coded destination type now, it's easier to hard-code + # the help. + "\tfile:[:rotate_length=][:max_rotated_files=]\n" + "\tSensible defaults are supplied for rotate_length and max_rotated_files\n" + "\tif they are not given.\n", + file=self.stdout, + ) + raise SystemExit(0) + class _EliotLogging(Service): """