From a1dcb3ed877966945d3a0540f8d52c5437121b68 Mon Sep 17 00:00:00 2001 From: Gregory Crosswhite Date: Tue, 21 Oct 2014 17:01:59 -0700 Subject: [PATCH] Now the list of export types in --help is generated from the plugins. --- jrnl/cli.py | 2 +- jrnl/plugins/__init__.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/jrnl/cli.py b/jrnl/cli.py index 7dd18c9b..2229b664 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -38,7 +38,7 @@ def parse_args(args=None): exporting = parser.add_argument_group('Export / Import', 'Options for transmogrifying your journal') exporting.add_argument('--short', dest='short', action="store_true", help='Show only titles or line containing the search tags') exporting.add_argument('--tags', dest='tags', action="store_true", help='Returns a list of all tags and number of occurences') - exporting.add_argument('--export', metavar='TYPE', dest='export', choices=plugins.BaseExporter.PLUGIN_NAMES, help='Export your journal. TYPE can be json, markdown, or text.', default=False, const=None) + exporting.add_argument('--export', metavar='TYPE', dest='export', choices=plugins.BaseExporter.PLUGIN_NAMES, help='Export your journal. TYPE can be %s.' % plugins.BaseExporter.get_plugin_types_string(), default=False, const=None) exporting.add_argument('-o', metavar='OUTPUT', dest='output', help='Optionally specifies output file when using --export. If OUTPUT is a directory, exports each entry into an individual file instead.', default=False, const=None) exporting.add_argument('--encrypt', metavar='FILENAME', dest='encrypt', help='Encrypts your existing journal with a new password', nargs='?', default=False, const=None) exporting.add_argument('--decrypt', metavar='FILENAME', dest='decrypt', help='Decrypts your journal and stores it in plain text', nargs='?', default=False, const=None) diff --git a/jrnl/plugins/__init__.py b/jrnl/plugins/__init__.py index f5129b3a..ecda8068 100644 --- a/jrnl/plugins/__init__.py +++ b/jrnl/plugins/__init__.py @@ -21,6 +21,17 @@ class PluginMeta(type): cls.PLUGINS.append(plugin) cls.PLUGIN_NAMES.extend(plugin.names) + def get_plugin_types_string(cls): + plugin_names = sorted(cls.PLUGIN_NAMES) + if not plugin_names: + return "(nothing)" + elif len(plugin_names) == 1: + return plugin_names[0] + elif len(plugin_names) == 2: + return plugin_names[0] + " or " + plugin_names[1] + else: + return ', '.join(plugin_names[:-1]) + ", or " + plugin_names[-1] + class BaseExporter(object): __metaclass__ = PluginMeta