Merge pull request #299 from gcgoogle/fix-hard-coded-export-type-list

Now the list of export types in --help is generated from the plugins.
This commit is contained in:
Manuel Ebert 2014-10-30 15:01:32 +01:00
commit 3024f2ba46
2 changed files with 12 additions and 1 deletions

View file

@ -38,7 +38,7 @@ def parse_args(args=None):
exporting = parser.add_argument_group('Export / Import', 'Options for transmogrifying your journal') 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('--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('--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('-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('--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) exporting.add_argument('--decrypt', metavar='FILENAME', dest='decrypt', help='Decrypts your journal and stores it in plain text', nargs='?', default=False, const=None)

View file

@ -21,6 +21,17 @@ class PluginMeta(type):
cls.PLUGINS.append(plugin) cls.PLUGINS.append(plugin)
cls.PLUGIN_NAMES.extend(plugin.names) 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): class BaseExporter(object):
__metaclass__ = PluginMeta __metaclass__ = PluginMeta